Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

20.6
-----
- [**] Users can experience orders not loading or loading slowly if they have a large number of custom fields. This has been fixed now. [https://github.com/woocommerce/woocommerce-ios/pull/14110]
- [*] Dashboard: Cards are now displayed in 2 columns on large screen sizes. [https://github.com/woocommerce/woocommerce-ios/pull/13983]
- [*] Jetpack setup: fixed issue checking site info after activating Jetpack for sites with Jetpack connection package. [https://github.com/woocommerce/woocommerce-ios/pull/13993]
- [*] Blaze: Campaign status is now updated immediately after being canceled. [https://github.com/woocommerce/woocommerce-ios/pull/13992]
Expand Down
5 changes: 2 additions & 3 deletions Yosemite/Yosemite/Stores/Order/OrdersUpsertUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,10 @@ struct OrdersUpsertUseCase {
/// Updates, inserts, or prunes the provided `storageOrder`'s custom fields using the provided `readOnlyOrder`'s custom fields
///
private func handleOrderCustomFields(_ readOnlyOrder: Networking.Order, _ storageOrder: Storage.Order, _ storage: StorageType) {
let storedMetaData = storageOrder.customFields
// Upsert the `customFields` from the `readOnlyOrder`
readOnlyOrder.customFields.forEach { readOnlyCustomField in
if let existingStorageMetaData = storage.loadOrderMetaData(siteID: readOnlyOrder.siteID,
orderID: storageOrder.orderID,
metadataID: readOnlyCustomField.metadataID) {
if let existingStorageMetaData = storedMetaData?.first(where: { $0.metadataID == readOnlyCustomField.metadataID }) {
existingStorageMetaData.update(with: readOnlyCustomField)
} else {
let newStorageMetaData = storage.insertNewObject(ofType: Storage.MetaData.self)
Expand Down
5 changes: 2 additions & 3 deletions Yosemite/Yosemite/Stores/ProductStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1162,11 +1162,10 @@ extension ProductStore {
/// Updates, inserts, or prunes the provided `storageProduct`'s custom fields using the provided `readOnlyProduct`'s custom fields
///
private func handleProductCustomFields(_ readOnlyProduct: Networking.Product, _ storageProduct: Storage.Product, _ storage: StorageType) {
let storedMetaData = storageProduct.customFields
// Upsert the `customFields` from the `readOnlyProduct`
readOnlyProduct.customFields.forEach { readOnlyCustomField in
if let existingStorageMetaData = storage.loadProductMetaData(siteID: readOnlyProduct.siteID,
productID: storageProduct.productID,
metadataID: readOnlyCustomField.metadataID) {
if let existingStorageMetaData = storedMetaData?.first(where: { $0.metadataID == readOnlyCustomField.metadataID }) {
existingStorageMetaData.update(with: readOnlyCustomField)
} else {
let newStorageMetaData = storage.insertNewObject(ofType: Storage.MetaData.self)
Expand Down
27 changes: 25 additions & 2 deletions Yosemite/YosemiteTests/Stores/Order/OrdersUpsertUseCaseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import XCTest

import Fakes
import Storage
import Networking

@testable import Networking
@testable import Yosemite

final class OrdersUpsertUseCaseTests: XCTestCase {
Expand Down Expand Up @@ -262,6 +261,30 @@ final class OrdersUpsertUseCaseTests: XCTestCase {
XCTAssertEqual(storageCustomField.toReadOnly(), customField)
}

func test_it_handles_large_number_of_custom_fields_for_order_and_product_without_deadlock_in_small_amount_of_time() throws {
// Given
let customFields = (1...2500).map { MetaData(metadataID: $0, key: "Key\($0)", value: "Value\($0)") }
let order = makeOrder().copy(siteID: 3, orderID: 98, customFields: customFields)
let product = Product.fake().copy(siteID: 3, productID: 99, customFields: customFields)
let backgroundContext = storageManager.writerDerivedStorage
let orderUseCase = OrdersUpsertUseCase(storage: backgroundContext)
let dispatcher = Dispatcher()
let network = MockNetwork()
let productStore = ProductStore(dispatcher: dispatcher, storageManager: storageManager, network: network)

// When
DispatchQueue.global(qos: .background).async {
orderUseCase.upsert([order])
productStore.upsertStoredProducts(readOnlyProducts: [product], in: backgroundContext)
backgroundContext.saveIfNeeded()
}

// Then
self.waitUntil {
self.viewStorage.countObjects(ofType: Storage.MetaData.self) == 5000
}
}

func test_it_persists_order_gift_card_in_storage() throws {
// Given
let giftCard = OrderGiftCard(giftCardID: 2, code: "SU9F-MGB5-KS5V-EZFT", amount: 20)
Expand Down