Skip to content

Commit 43c2942

Browse files
authored
Merge branch 'trunk' into fix/14593-fix-pos-aggregate-modal-memory-leak-2
2 parents 5c39bca + ceb70bd commit 43c2942

File tree

10 files changed

+221
-153
lines changed

10 files changed

+221
-153
lines changed

WooCommerce/Classes/POS/Controllers/PointOfSaleItemsController.swift

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Foundation
22
import Observation
33
import enum Yosemite.POSItem
44
import protocol Yosemite.PointOfSaleItemServiceProtocol
5+
import enum Yosemite.PointOfSaleItemServiceError
56
import struct Yosemite.POSVariableParentProduct
67
import class Yosemite.Store
78

@@ -162,26 +163,33 @@ private extension PointOfSaleItemsController {
162163
/// - Returns: A boolean that indicates whether there is next page for the paginated items.
163164
@MainActor
164165
func fetchItems(pageNumber: Int, appendToExistingItems: Bool = true) async throws -> Bool {
165-
let pagedItems = try await itemProvider.providePointOfSaleItems(pageNumber: pageNumber)
166-
let newItems = pagedItems.items
167-
var allItems = appendToExistingItems ? itemsViewState.itemsStack.root.items : []
168-
let uniqueNewItems = newItems.filter { newItem in
169-
// Note that this uniquing won't currently work, as POSItem has a UUID.
170-
!allItems.contains(newItem)
171-
}
172-
allItems.append(contentsOf: uniqueNewItems)
173-
if allItems.isEmpty {
174-
itemsViewState.containerState = .empty
175-
itemsViewState.itemsStack = ItemsStackState(root: .loaded([], hasMoreItems: false),
176-
itemStates: [:])
177-
} else {
178-
let itemStates = itemsViewState.itemsStack.itemStates
179-
.filter { allItems.contains($0.key) }
166+
do {
167+
let pagedItems = try await itemProvider.providePointOfSaleItems(pageNumber: pageNumber)
168+
let newItems = pagedItems.items
169+
var allItems = appendToExistingItems ? itemsViewState.itemsStack.root.items : []
170+
let uniqueNewItems = newItems.filter { newItem in
171+
// Note that this uniquing won't currently work, as POSItem has a UUID.
172+
!allItems.contains(newItem)
173+
}
174+
allItems.append(contentsOf: uniqueNewItems)
175+
if allItems.isEmpty {
176+
itemsViewState.containerState = .empty
177+
itemsViewState.itemsStack = ItemsStackState(root: .loaded([], hasMoreItems: false),
178+
itemStates: [:])
179+
} else {
180+
let itemStates = itemsViewState.itemsStack.itemStates
181+
.filter { allItems.contains($0.key) }
182+
itemsViewState.containerState = .content
183+
itemsViewState.itemsStack = ItemsStackState(root: .loaded(allItems, hasMoreItems: pagedItems.hasMorePages),
184+
itemStates: itemStates)
185+
}
186+
return pagedItems.hasMorePages
187+
} catch PointOfSaleItemServiceError.requestCancelled {
180188
itemsViewState.containerState = .content
181-
itemsViewState.itemsStack = ItemsStackState(root: .loaded(allItems, hasMoreItems: pagedItems.hasMorePages),
182-
itemStates: itemStates)
189+
itemsViewState.itemsStack.root = .loaded(itemsViewState.itemsStack.root.items, hasMoreItems: true)
190+
// Assume that we have more pages since we'd made a request, and it was cancelled
191+
return true
183192
}
184-
return pagedItems.hasMorePages
185193
}
186194

187195
/// Fetches variation items given a page number and appends new unique items to the existing items array.
@@ -192,20 +200,28 @@ private extension PointOfSaleItemsController {
192200
parentItem: POSItem,
193201
pageNumber: Int,
194202
appendToExistingItems: Bool = true) async throws -> Bool {
195-
let pagedItems = try await itemProvider.providePointOfSaleVariationItems(
196-
for: parentProduct,
197-
pageNumber: pageNumber
198-
)
199-
let newItems = pagedItems.items
200-
var allItems: [POSItem] = appendToExistingItems ? (itemsViewState.itemsStack.itemStates[parentItem]?.items ?? []) : []
201-
let uniqueNewItems = newItems.filter { newItem in
202-
// Note that this uniquing won't currently work, as POSItem has a UUID.
203-
!allItems.contains(newItem)
204-
}
205-
allItems.append(contentsOf: uniqueNewItems)
203+
do {
204+
let pagedItems = try await itemProvider.providePointOfSaleVariationItems(
205+
for: parentProduct,
206+
pageNumber: pageNumber
207+
)
208+
let newItems = pagedItems.items
209+
var allItems: [POSItem] = appendToExistingItems ? (itemsViewState.itemsStack.itemStates[parentItem]?.items ?? []) : []
210+
let uniqueNewItems = newItems.filter { newItem in
211+
// Note that this uniquing won't currently work, as POSItem has a UUID.
212+
!allItems.contains(newItem)
213+
}
214+
allItems.append(contentsOf: uniqueNewItems)
206215

207-
updateState(for: parentItem, to: .loaded(allItems, hasMoreItems: pagedItems.hasMorePages))
208-
return pagedItems.hasMorePages
216+
updateState(for: parentItem, to: .loaded(allItems, hasMoreItems: pagedItems.hasMorePages))
217+
return pagedItems.hasMorePages
218+
} catch PointOfSaleItemServiceError.requestCancelled {
219+
itemsViewState.containerState = .content
220+
updateState(for: parentItem, to: .loaded(itemsViewState.itemsStack.itemStates[parentItem]?.items ?? [],
221+
hasMoreItems: true))
222+
// Assume that we have more pages since we'd made a request, and it was cancelled
223+
return true
224+
}
209225
}
210226
}
211227

WooCommerce/WooCommerce.xcodeproj/xcshareddata/xcschemes/StoreWidgetsExtension.xcscheme

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,6 @@
4343
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
4444
shouldUseLaunchSchemeArgsEnv = "YES">
4545
<Testables>
46-
<TestableReference
47-
skipped = "NO"
48-
parallelizable = "YES">
49-
<BuildableReference
50-
BuildableIdentifier = "primary"
51-
BlueprintIdentifier = "3F0904072D26A40800D8ACCE"
52-
BuildableName = "WordPressAuthenticatorTests.xctest"
53-
BlueprintName = "WordPressAuthenticatorTests"
54-
ReferencedContainer = "container:WooCommerce.xcodeproj">
55-
</BuildableReference>
56-
</TestableReference>
5746
</Testables>
5847
</TestAction>
5948
<LaunchAction

WooCommerce/WooCommerce.xcodeproj/xcshareddata/xcschemes/Woo Watch App.xcscheme

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,6 @@
4242
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
4343
shouldUseLaunchSchemeArgsEnv = "YES"
4444
shouldAutocreateTestPlan = "YES">
45-
<Testables>
46-
<TestableReference
47-
skipped = "NO"
48-
parallelizable = "YES">
49-
<BuildableReference
50-
BuildableIdentifier = "primary"
51-
BlueprintIdentifier = "3F0904072D26A40800D8ACCE"
52-
BuildableName = "WordPressAuthenticatorTests.xctest"
53-
BlueprintName = "WordPressAuthenticatorTests"
54-
ReferencedContainer = "container:WooCommerce.xcodeproj">
55-
</BuildableReference>
56-
</TestableReference>
57-
</Testables>
5845
</TestAction>
5946
<LaunchAction
6047
buildConfiguration = "Debug"

WooCommerce/WooCommerce.xcodeproj/xcshareddata/xcschemes/WooCommerce Alpha.xcscheme

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,6 @@
4848
ReferencedContainer = "container:WooCommerce.xcodeproj">
4949
</BuildableReference>
5050
</TestableReference>
51-
<TestableReference
52-
skipped = "NO"
53-
parallelizable = "YES">
54-
<BuildableReference
55-
BuildableIdentifier = "primary"
56-
BlueprintIdentifier = "3F0904072D26A40800D8ACCE"
57-
BuildableName = "WordPressAuthenticatorTests.xctest"
58-
BlueprintName = "WordPressAuthenticatorTests"
59-
ReferencedContainer = "container:WooCommerce.xcodeproj">
60-
</BuildableReference>
61-
</TestableReference>
6251
</Testables>
6352
</TestAction>
6453
<LaunchAction

WooCommerce/WooCommerce.xcodeproj/xcshareddata/xcschemes/WooCommerce IAP.xcscheme

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,6 @@
9696
ReferencedContainer = "container:WooCommerce.xcodeproj">
9797
</BuildableReference>
9898
</TestableReference>
99-
<TestableReference
100-
skipped = "NO"
101-
parallelizable = "YES">
102-
<BuildableReference
103-
BuildableIdentifier = "primary"
104-
BlueprintIdentifier = "3F0904072D26A40800D8ACCE"
105-
BuildableName = "WordPressAuthenticatorTests.xctest"
106-
BlueprintName = "WordPressAuthenticatorTests"
107-
ReferencedContainer = "container:WooCommerce.xcodeproj">
108-
</BuildableReference>
109-
</TestableReference>
11099
</Testables>
111100
</TestAction>
112101
<LaunchAction

WooCommerce/WooCommerce.xcodeproj/xcshareddata/xcschemes/WooCommerceScreenshots.xcscheme

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,6 @@
2222
ReferencedContainer = "container:WooCommerce.xcodeproj">
2323
</BuildableReference>
2424
</TestableReference>
25-
<TestableReference
26-
skipped = "YES">
27-
<BuildableReference
28-
BuildableIdentifier = "primary"
29-
BlueprintIdentifier = "CCDC49C923FFFFF4003166BA"
30-
BuildableName = "WooCommerceUITests.xctest"
31-
BlueprintName = "WooCommerceUITests"
32-
ReferencedContainer = "container:WooCommerce.xcodeproj">
33-
</BuildableReference>
34-
</TestableReference>
35-
<TestableReference
36-
skipped = "NO"
37-
parallelizable = "YES">
38-
<BuildableReference
39-
BuildableIdentifier = "primary"
40-
BlueprintIdentifier = "3F0904072D26A40800D8ACCE"
41-
BuildableName = "WordPressAuthenticatorTests.xctest"
42-
BlueprintName = "WordPressAuthenticatorTests"
43-
ReferencedContainer = "container:WooCommerce.xcodeproj">
44-
</BuildableReference>
45-
</TestableReference>
4625
</Testables>
4726
</TestAction>
4827
<LaunchAction
@@ -78,6 +57,15 @@
7857
savedToolIdentifier = ""
7958
useCustomWorkingDirectory = "NO"
8059
debugDocumentVersioning = "YES">
60+
<MacroExpansion>
61+
<BuildableReference
62+
BuildableIdentifier = "primary"
63+
BlueprintIdentifier = "B56DB3C52049BFAA00D4AA8E"
64+
BuildableName = "WooCommerce.app"
65+
BlueprintName = "WooCommerce"
66+
ReferencedContainer = "container:WooCommerce.xcodeproj">
67+
</BuildableReference>
68+
</MacroExpansion>
8169
</ProfileAction>
8270
<AnalyzeAction
8371
buildConfiguration = "Debug">

WooCommerce/WooCommerce.xcodeproj/xcshareddata/xcschemes/WooCommerceUITests.xcscheme

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,6 @@
107107
ReferencedContainer = "container:WooCommerce.xcodeproj">
108108
</BuildableReference>
109109
</TestableReference>
110-
<TestableReference
111-
skipped = "NO"
112-
parallelizable = "YES">
113-
<BuildableReference
114-
BuildableIdentifier = "primary"
115-
BlueprintIdentifier = "3F0904072D26A40800D8ACCE"
116-
BuildableName = "WordPressAuthenticatorTests.xctest"
117-
BlueprintName = "WordPressAuthenticatorTests"
118-
ReferencedContainer = "container:WooCommerce.xcodeproj">
119-
</BuildableReference>
120-
</TestableReference>
121110
</Testables>
122111
</TestAction>
123112
<LaunchAction

0 commit comments

Comments
 (0)