@@ -8,12 +8,6 @@ protocol POSCatalogPersistenceServiceProtocol {
88 /// - catalog: The catalog to persist
99 /// - siteID: The site ID to associate the catalog with
1010 func replaceAllCatalogData( _ catalog: POSCatalog , siteID: Int64 ) async throws
11-
12- /// Persists incremental catalog data (insert/update)
13- /// - Parameters:
14- /// - catalog: The catalog difference to persist
15- /// - siteID: The site ID to associate the catalog with
16- func persistIncrementalCatalogData( _ catalog: POSCatalog , siteID: Int64 ) async throws
1711}
1812
1913final class POSCatalogPersistenceService : POSCatalogPersistenceServiceProtocol {
@@ -74,70 +68,6 @@ final class POSCatalogPersistenceService: POSCatalogPersistenceServiceProtocol {
7468 " \( variationImageCount) variation images, \( variationAttributeCount) variation attributes " )
7569 }
7670 }
77-
78- func persistIncrementalCatalogData( _ catalog: POSCatalog , siteID: Int64 ) async throws {
79- DDLogInfo ( " 💾 Persisting incremental catalog with \( catalog. products. count) products and \( catalog. variations. count) variations " )
80-
81- try await grdbManager. databaseConnection. write { db in
82- let site = PersistedSite ( id: siteID)
83- try site. insert ( db, onConflict: . ignore)
84-
85- for product in catalog. productsToPersist {
86- try product. insert ( db, onConflict: . replace)
87- }
88-
89- let productIDs = catalog. products. map { $0. productID } . map { String ( $0) } . joined ( separator: " , " )
90-
91- try PersistedProductImage
92- . filter ( sql: " \( PersistedProductImage . Columns. productID. name) IN ( \( productIDs) ) " )
93- . deleteAll ( db)
94- for image in catalog. productImagesToPersist {
95- try image. insert ( db, onConflict: . replace)
96- }
97-
98- try PersistedProductAttribute
99- . filter ( sql: " \( PersistedProductAttribute . Columns. productID. name) IN ( \( productIDs) ) " )
100- . deleteAll ( db)
101- for var attribute in catalog. productAttributesToPersist {
102- try attribute. insert ( db)
103- }
104-
105- for variation in catalog. variationsToPersist {
106- try variation. insert ( db, onConflict: . replace)
107- }
108-
109- let variationIDs = catalog. variations. map { $0. productVariationID } . map { String ( $0) } . joined ( separator: " , " )
110-
111- try PersistedProductVariationImage
112- . filter ( sql: " \( PersistedProductVariationImage . Columns. productVariationID. name) IN ( \( variationIDs) ) " )
113- . deleteAll ( db)
114- for image in catalog. variationImagesToPersist {
115- try image. insert ( db, onConflict: . replace)
116- }
117-
118- try PersistedProductVariationAttribute
119- . filter ( sql: " \( PersistedProductVariationAttribute . Columns. productVariationID. name) IN ( \( variationIDs) ) " )
120- . deleteAll ( db)
121- for var attribute in catalog. variationAttributesToPersist {
122- try attribute. insert ( db)
123- }
124- }
125-
126- DDLogInfo ( " ✅ Incremental catalog persistence complete " )
127-
128- try await grdbManager. databaseConnection. read { db in
129- let productCount = try PersistedProduct . fetchCount ( db)
130- let productImageCount = try PersistedProductImage . fetchCount ( db)
131- let productAttributeCount = try PersistedProductAttribute . fetchCount ( db)
132- let variationCount = try PersistedProductVariation . fetchCount ( db)
133- let variationImageCount = try PersistedProductVariationImage . fetchCount ( db)
134- let variationAttributeCount = try PersistedProductVariationAttribute . fetchCount ( db)
135-
136- DDLogInfo ( " Total after incremental update: \( productCount) products, \( productImageCount) product images, " +
137- " \( productAttributeCount) product attributes, \( variationCount) variations, " +
138- " \( variationImageCount) variation images, \( variationAttributeCount) variation attributes " )
139- }
140- }
14171}
14272
14373private extension POSCatalog {
0 commit comments