Skip to content

Commit 68573ae

Browse files
committed
Revert persistence changes for incremental sync for a separate PR.
1 parent ebb3339 commit 68573ae

File tree

8 files changed

+8
-552
lines changed

8 files changed

+8
-552
lines changed

Modules/Sources/Storage/GRDB/Model/PersistedProductAttribute.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extension PersistedProductAttribute: FetchableRecord, MutablePersistableRecord {
3434

3535
public enum Columns {
3636
static let id = Column(CodingKeys.id)
37-
public static let productID = Column(CodingKeys.productID)
37+
static let productID = Column(CodingKeys.productID)
3838
static let name = Column(CodingKeys.name)
3939
static let position = Column(CodingKeys.position)
4040
static let visible = Column(CodingKeys.visible)

Modules/Sources/Storage/GRDB/Model/PersistedProductImage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extension PersistedProductImage: FetchableRecord, PersistableRecord {
3434

3535
public enum Columns {
3636
static let id = Column(CodingKeys.id)
37-
public static let productID = Column(CodingKeys.productID)
37+
static let productID = Column(CodingKeys.productID)
3838
static let dateCreated = Column(CodingKeys.dateCreated)
3939
static let dateModified = Column(CodingKeys.dateModified)
4040
static let src = Column(CodingKeys.src)

Modules/Sources/Storage/GRDB/Model/PersistedProductVariationAttribute.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extension PersistedProductVariationAttribute: FetchableRecord, MutablePersistabl
2626

2727
public enum Columns {
2828
static let id = Column(CodingKeys.id)
29-
public static let productVariationID = Column(CodingKeys.productVariationID)
29+
static let productVariationID = Column(CodingKeys.productVariationID)
3030
static let name = Column(CodingKeys.name)
3131
static let option = Column(CodingKeys.option)
3232
}

Modules/Sources/Storage/GRDB/Model/PersistedProductVariationImage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extension PersistedProductVariationImage: FetchableRecord, PersistableRecord {
3434

3535
public enum Columns {
3636
static let id = Column(CodingKeys.id)
37-
public static let productVariationID = Column(CodingKeys.productVariationID)
37+
static let productVariationID = Column(CodingKeys.productVariationID)
3838
static let dateCreated = Column(CodingKeys.dateCreated)
3939
static let dateModified = Column(CodingKeys.dateModified)
4040
static let src = Column(CodingKeys.src)

Modules/Sources/Yosemite/Tools/POS/POSCatalogIncrementalSyncService.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,22 @@ public protocol POSCatalogIncrementalSyncServiceProtocol {
2020
public final class POSCatalogIncrementalSyncService: POSCatalogIncrementalSyncServiceProtocol {
2121
private let syncRemote: POSCatalogSyncRemoteProtocol
2222
private let batchSize: Int
23-
private let persistenceService: POSCatalogPersistenceServiceProtocol
2423
private var lastIncrementalSyncDates: [Int64: Date] = [:]
2524
private let batchedLoader: BatchedRequestLoader
2625

27-
public convenience init?(credentials: Credentials?, batchSize: Int = 1, grdbManager: GRDBManagerProtocol) {
26+
public convenience init?(credentials: Credentials?, batchSize: Int = 1) {
2827
guard let credentials else {
2928
DDLogError("⛔️ Could not create POSCatalogIncrementalSyncService due missing credentials")
3029
return nil
3130
}
3231
let network = AlamofireNetwork(credentials: credentials, ensuresSessionManagerIsInitialized: true)
3332
let syncRemote = POSCatalogSyncRemote(network: network)
34-
let persistenceService = POSCatalogPersistenceService(grdbManager: grdbManager)
35-
self.init(syncRemote: syncRemote, batchSize: batchSize, persistenceService: persistenceService)
33+
self.init(syncRemote: syncRemote, batchSize: batchSize)
3634
}
3735

38-
init(syncRemote: POSCatalogSyncRemoteProtocol, batchSize: Int, persistenceService: POSCatalogPersistenceServiceProtocol) {
36+
init(syncRemote: POSCatalogSyncRemoteProtocol, batchSize: Int) {
3937
self.syncRemote = syncRemote
4038
self.batchSize = batchSize
41-
self.persistenceService = persistenceService
4239
self.batchedLoader = BatchedRequestLoader(batchSize: batchSize)
4340
}
4441

@@ -54,8 +51,7 @@ public final class POSCatalogIncrementalSyncService: POSCatalogIncrementalSyncSe
5451
let catalog = try await loadCatalog(for: siteID, modifiedAfter: modifiedAfter, syncRemote: syncRemote)
5552
DDLogInfo("✅ Loaded \(catalog.products.count) products and \(catalog.variations.count) variations for siteID \(siteID)")
5653

57-
try await persistenceService.persistIncrementalCatalogData(catalog, siteID: siteID)
58-
DDLogInfo("✅ Persisted \(catalog.products.count) products and \(catalog.variations.count) variations to database for siteID \(siteID)")
54+
// TODO: WOOMOB-1298 - persist to database
5955

6056
// TODO: WOOMOB-1289 - replace with store settings persistence
6157
lastIncrementalSyncDates[siteID] = syncStartDate

Modules/Sources/Yosemite/Tools/POS/POSCatalogPersistenceService.swift

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1913
final 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

14373
private extension POSCatalog {

Modules/Tests/YosemiteTests/Tools/POS/POSCatalogIncrementalSyncServiceTests.swift

Lines changed: 0 additions & 196 deletions
This file was deleted.

0 commit comments

Comments
 (0)