Skip to content

Commit 02c2794

Browse files
authored
Improve data fetching in Order Details, to avoid I/O performance on the main thread (#14999)
2 parents 2f63583 + bbfb18c commit 02c2794

File tree

27 files changed

+166
-124
lines changed

27 files changed

+166
-124
lines changed

Fakes/Fakes/Networking.generated.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,8 @@ extension Networking.Order {
871871
customFields: .fake(),
872872
renewalSubscriptionID: .fake(),
873873
appliedGiftCards: .fake(),
874-
attributionInfo: .fake()
874+
attributionInfo: .fake(),
875+
shippingLabels: .fake()
875876
)
876877
}
877878
}

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,11 @@
472472
453954D22C90D84200A3E64A /* meta-data-products-and-orders.json in Resources */ = {isa = PBXBuildFile; fileRef = 453954D12C90D84200A3E64A /* meta-data-products-and-orders.json */; };
473473
453954D42C90E81300A3E64A /* MetaDataRemoteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 453954D32C90E81300A3E64A /* MetaDataRemoteTests.swift */; };
474474
453954D62C9193BC00A3E64A /* meta-data-products-orders-update.json in Resources */ = {isa = PBXBuildFile; fileRef = 453954D52C9193BC00A3E64A /* meta-data-products-orders-update.json */; };
475+
453B33FD2D47F1F4005C05B0 /* ShippingLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02C254A7256373AB00A04423 /* ShippingLabel.swift */; };
476+
453B33FE2D47F1FB005C05B0 /* ShippingLabelStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02C254AB2563781800A04423 /* ShippingLabelStatus.swift */; };
477+
453B33FF2D47F203005C05B0 /* ShippingLabelRefund.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02C2549F25636F6900A04423 /* ShippingLabelRefund.swift */; };
478+
453B34002D47F20A005C05B0 /* ShippingLabelRefundStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02C254AF256378D000A04423 /* ShippingLabelRefundStatus.swift */; };
479+
453B34012D47F22C005C05B0 /* ShippingLabelAddress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02C2549925636E1500A04423 /* ShippingLabelAddress.swift */; };
475480
45551F122523E7F1007EF104 /* UserAgent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45551F112523E7F1007EF104 /* UserAgent.swift */; };
476481
45551F142523E7FF007EF104 /* UserAgentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45551F132523E7FF007EF104 /* UserAgentTests.swift */; };
477482
4568E2222459ADC60007E478 /* SitePostsRemote.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4568E2212459ADC60007E478 /* SitePostsRemote.swift */; };
@@ -5014,11 +5019,13 @@
50145019
2680B0D22BED5A4C00E7F1D8 /* AuthenticatedRESTRequest.swift in Sources */,
50155020
2680B0D02BED5A1900E7F1D8 /* WooConstants.swift in Sources */,
50165021
2680B0CF2BED59CE00E7F1D8 /* ApplicationPasswordStorage.swift in Sources */,
5022+
453B34002D47F20A005C05B0 /* ShippingLabelRefundStatus.swift in Sources */,
50175023
2680B0CB2BED58B200E7F1D8 /* ApplicationPasswordNameAndUUID.swift in Sources */,
50185024
26373E0A2BFCEAAF008E6735 /* OrderItemTax.swift in Sources */,
50195025
2680B0CC2BED58B200E7F1D8 /* ApplicationPassword.swift in Sources */,
50205026
26373E122BFCEDB7008E6735 /* OrderFeeLine.swift in Sources */,
50215027
26F2CADD2BED579100F9A5E7 /* ApplicationPasswordUseCase.swift in Sources */,
5028+
453B33FF2D47F203005C05B0 /* ShippingLabelRefund.swift in Sources */,
50225029
26F2CADA2BED578200F9A5E7 /* RequestProcessor.swift in Sources */,
50235030
26F2CADB2BED578200F9A5E7 /* RequestAuthenticator.swift in Sources */,
50245031
26F2CADC2BED578200F9A5E7 /* RequestConverter.swift in Sources */,
@@ -5031,6 +5038,7 @@
50315038
263A6DBC2BEAA49B00C292B2 /* AnyDecodable.swift in Sources */,
50325039
263A6DBD2BEAA49B00C292B2 /* AnyEncodable.swift in Sources */,
50335040
263A6DB92BEAA46F00C292B2 /* SiteSummaryStatsMapper.swift in Sources */,
5041+
453B33FD2D47F1F4005C05B0 /* ShippingLabel.swift in Sources */,
50345042
26373E112BFCEDAE008E6735 /* OrderRefundCondensed.swift in Sources */,
50355043
263A6DBA2BEAA46F00C292B2 /* SiteSummaryStats.swift in Sources */,
50365044
263A6DB62BEAA46000C292B2 /* SiteVisitStatsMapper.swift in Sources */,
@@ -5089,6 +5097,7 @@
50895097
26CFDEE12C0295EA005ABC31 /* MetaContainer.swift in Sources */,
50905098
26373E152BFCEDE9008E6735 /* OrderGiftCard.swift in Sources */,
50915099
269014CB2BEA9253006056E0 /* JetpackRequest.swift in Sources */,
5100+
453B34012D47F22C005C05B0 /* ShippingLabelAddress.swift in Sources */,
50925101
269014CA2BEA924B006056E0 /* NetworkError.swift in Sources */,
50935102
26373E092BFCEA90008E6735 /* OrderItemProductAddOn.swift in Sources */,
50945103
26373E162BFCEDFD008E6735 /* OrderAttributionInfo.swift in Sources */,
@@ -5101,6 +5110,7 @@
51015110
269014C32BEA9134006056E0 /* Mapper.swift in Sources */,
51025111
269014C22BEA912D006056E0 /* Request.swift in Sources */,
51035112
26373E182BFCEF79008E6735 /* KeyedDecodingContainer+Woo.swift in Sources */,
5113+
453B33FE2D47F1FB005C05B0 /* ShippingLabelStatus.swift in Sources */,
51045114
26373E202BFCF6A7008E6735 /* EntityDateModifiedMapper.swift in Sources */,
51055115
26CFDEE02C0295E1005ABC31 /* NoteRange.swift in Sources */,
51065116
26CFDEDE2C0295CB005ABC31 /* NoteBlock.swift in Sources */,

Networking/Networking/Model/Copiable/Models+Copiable.generated.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,8 @@ extension Networking.Order {
13951395
customFields: CopiableProp<[MetaData]> = .copy,
13961396
renewalSubscriptionID: NullableCopiableProp<String> = .copy,
13971397
appliedGiftCards: CopiableProp<[OrderGiftCard]> = .copy,
1398-
attributionInfo: NullableCopiableProp<OrderAttributionInfo> = .copy
1398+
attributionInfo: NullableCopiableProp<OrderAttributionInfo> = .copy,
1399+
shippingLabels: CopiableProp<[ShippingLabel]> = .copy
13991400
) -> Networking.Order {
14001401
let siteID = siteID ?? self.siteID
14011402
let orderID = orderID ?? self.orderID
@@ -1435,6 +1436,7 @@ extension Networking.Order {
14351436
let renewalSubscriptionID = renewalSubscriptionID ?? self.renewalSubscriptionID
14361437
let appliedGiftCards = appliedGiftCards ?? self.appliedGiftCards
14371438
let attributionInfo = attributionInfo ?? self.attributionInfo
1439+
let shippingLabels = shippingLabels ?? self.shippingLabels
14381440

14391441
return Networking.Order(
14401442
siteID: siteID,
@@ -1474,7 +1476,8 @@ extension Networking.Order {
14741476
customFields: customFields,
14751477
renewalSubscriptionID: renewalSubscriptionID,
14761478
appliedGiftCards: appliedGiftCards,
1477-
attributionInfo: attributionInfo
1479+
attributionInfo: attributionInfo,
1480+
shippingLabels: shippingLabels
14781481
)
14791482
}
14801483
}

Networking/Networking/Model/Order.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable {
6161
///
6262
public let attributionInfo: OrderAttributionInfo?
6363

64+
/// Shipping labels associated with the order
65+
///
66+
public let shippingLabels: [ShippingLabel]
67+
6468
/// Order struct initializer.
6569
///
6670
public init(siteID: Int64,
@@ -100,7 +104,8 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable {
100104
customFields: [MetaData],
101105
renewalSubscriptionID: String?,
102106
appliedGiftCards: [OrderGiftCard],
103-
attributionInfo: OrderAttributionInfo?) {
107+
attributionInfo: OrderAttributionInfo?,
108+
shippingLabels: [ShippingLabel]) {
104109

105110
self.siteID = siteID
106111
self.orderID = orderID
@@ -145,6 +150,7 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable {
145150
self.renewalSubscriptionID = renewalSubscriptionID
146151
self.appliedGiftCards = appliedGiftCards
147152
self.attributionInfo = attributionInfo
153+
self.shippingLabels = shippingLabels
148154
}
149155

150156

@@ -239,6 +245,11 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable {
239245
return OrderAttributionInfo(metaData: allOrderMetaData)
240246
}()
241247

248+
// Shipping labels
249+
/// This will be an empty array by default because it's not directly parsed from the Order details, so it won't be decoded.
250+
/// It's fetched with a specific API request, while at the same time it has a relationship in Core Data with Order.
251+
let shippingLabels: [ShippingLabel] = []
252+
242253
self.init(siteID: siteID,
243254
orderID: orderID,
244255
parentID: parentID,
@@ -276,7 +287,8 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable {
276287
customFields: customFields,
277288
renewalSubscriptionID: renewalSubscriptionID,
278289
appliedGiftCards: appliedGiftCards,
279-
attributionInfo: attributionInfo)
290+
attributionInfo: attributionInfo,
291+
shippingLabels: shippingLabels)
280292
}
281293

282294
public static var empty: Order {
@@ -317,7 +329,8 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable {
317329
customFields: [],
318330
renewalSubscriptionID: nil,
319331
appliedGiftCards: [],
320-
attributionInfo: nil)
332+
attributionInfo: nil,
333+
shippingLabels: [])
321334
}
322335
}
323336

@@ -365,6 +378,7 @@ internal extension Order {
365378
case taxLines = "tax_lines"
366379
case metadata = "meta_data"
367380
case giftCards = "gift_cards"
381+
case shippingLabels = "shipping_labels"
368382
}
369383
}
370384

@@ -407,7 +421,8 @@ extension Order: Equatable {
407421
lhs.items.count == rhs.items.count &&
408422
lhs.items.sorted() == rhs.items.sorted() &&
409423
lhs.customerNote == rhs.customerNote &&
410-
lhs.attributionInfo == rhs.attributionInfo
424+
lhs.attributionInfo == rhs.attributionInfo &&
425+
lhs.shippingLabels == rhs.shippingLabels
411426
}
412427
}
413428

Networking/Networking/Model/ShippingLabel/Enums/ShippingLabelRefundStatus.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22
import Codegen
33

44
/// The status of shipping label refund.
5-
public enum ShippingLabelRefundStatus: GeneratedFakeable {
5+
public enum ShippingLabelRefundStatus: Sendable, GeneratedFakeable {
66
case pending
77
case unknown
88
}

Networking/Networking/Model/ShippingLabel/Enums/ShippingLabelStatus.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22
import Codegen
33

44
/// The status of shipping label.
5-
public enum ShippingLabelStatus: GeneratedFakeable {
5+
public enum ShippingLabelStatus: Sendable, GeneratedFakeable {
66
case purchased
77
case purchaseError
88
case purchaseInProgress

Networking/Networking/Model/ShippingLabel/ShippingLabel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Codegen
33

44
/// Represents a Shipping Label.
55
///
6-
public struct ShippingLabel: Equatable, GeneratedCopiable, GeneratedFakeable {
6+
public struct ShippingLabel: Equatable, Sendable, GeneratedCopiable, GeneratedFakeable {
77
/// The remote ID of the site that owns this shipping label.
88
public let siteID: Int64
99

Networking/Networking/Model/ShippingLabel/ShippingLabelAddress.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Codegen
33

44
/// Represents a Shipping Label Address.
55
///
6-
public struct ShippingLabelAddress: GeneratedCopiable, Equatable, GeneratedFakeable {
6+
public struct ShippingLabelAddress: GeneratedCopiable, Equatable, Sendable, GeneratedFakeable {
77
/// The name of the company at the address.
88
public let company: String
99

Networking/Networking/Model/ShippingLabel/ShippingLabelRefund.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Codegen
33

44
/// Represents a Shipping Label Refund.
55
///
6-
public struct ShippingLabelRefund: Equatable, GeneratedFakeable {
6+
public struct ShippingLabelRefund: Equatable, Sendable, GeneratedFakeable {
77
/// The date of refund request.
88
public let dateRequested: Date
99

RELEASE-NOTES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
22.1
55
-----
6-
76
- [*] Order Creation: Fixed an issue where order recalculation would stop working after canceling a confirmation with unsaved changes [https://github.com/woocommerce/woocommerce-ios/pull/15392].
7+
- [internal] Improve data fetching in Order Details, to avoid I/O performance on the main thread. [https://github.com/woocommerce/woocommerce-ios/pull/14999]
88

99
22.0
1010
-----

0 commit comments

Comments
 (0)