Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -92,63 +92,34 @@ class WooPosLocalCatalogSyncRepository @Inject constructor(
return catalogSizeCheckResult.toPosLocalCatalogSyncFailure()
}

val productSyncResult = syncProducts(site, modifiedAfterGmt, pageSize, maxPages)
if (productSyncResult is WooPosSyncResult.Failed) {
return productSyncResult.toPosLocalCatalogSyncFailure()
val syncResult = posSyncAction.syncCatalog(site, modifiedAfterGmt, pageSize, maxPages)
if (syncResult is WooPosSyncResult.Failed) {
return syncResult.toPosLocalCatalogSyncFailure()
}

val variationSyncResult = syncVariations(site, modifiedAfterGmt, pageSize, maxPages)
if (variationSyncResult is WooPosSyncResult.Failed) {
return variationSyncResult.toPosLocalCatalogSyncFailure()
}

val syncDuration = System.currentTimeMillis() - startTime

return PosLocalCatalogSyncResult.Success(
productsSynced = (productSyncResult as WooPosSyncResult.Success).syncedCount,
variationsSynced = (variationSyncResult as WooPosSyncResult.Success).syncedCount,
syncDurationMs = syncDuration
)
}
val successResult = syncResult as WooPosSyncResult.Success

private suspend fun syncProducts(
site: SiteModel,
modifiedAfterGmt: String?,
pageSize: Int,
maxPages: Int
): WooPosSyncResult {
val result = posSyncAction.syncProducts(site, modifiedAfterGmt, pageSize, maxPages)

if (result is WooPosSyncResult.Success) {
result.serverDate?.let { serverDate ->
syncTimestampManager.parseTimestampFromApi(serverDate)?.let { timestamp ->
syncTimestampManager.storeProductsLastSyncTimestamp(timestamp)
logger.d("Stored products sync timestamp: $serverDate")
}
successResult.productsServerDate?.let { serverDate ->
syncTimestampManager.parseTimestampFromApi(serverDate)?.let { timestamp ->
syncTimestampManager.storeProductsLastSyncTimestamp(timestamp)
logger.d("Stored products sync timestamp: $serverDate")
}
}

return result
}

private suspend fun syncVariations(
site: SiteModel,
modifiedAfterGmt: String?,
pageSize: Int,
maxPages: Int
): WooPosSyncResult {
val result = posSyncAction.syncVariations(site, modifiedAfterGmt, pageSize, maxPages)

if (result is WooPosSyncResult.Success) {
result.serverDate?.let { serverDate ->
syncTimestampManager.parseTimestampFromApi(serverDate)?.let { timestamp ->
syncTimestampManager.storeVariationsLastSyncTimestamp(timestamp)
logger.d("Stored variations sync timestamp: $serverDate")
}
successResult.variationsServerDate?.let { serverDate ->
syncTimestampManager.parseTimestampFromApi(serverDate)?.let { timestamp ->
syncTimestampManager.storeVariationsLastSyncTimestamp(timestamp)
logger.d("Stored variations sync timestamp: $serverDate")
}
}

return result
val syncDuration = System.currentTimeMillis() - startTime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 n.p.: I'm wondering if it would be better to inject the current time via DateTimeProvider and replace all 3 System::currentTimeMillis calls with DateTimeProvider::now already. Currently, it's not a big deal since we are not even asserting the syncDurationMs value in tests, but it can avoid making tests non-deterministic by accident in the future.

Copy link
Contributor Author

@malinajirka malinajirka Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 5c95269


return PosLocalCatalogSyncResult.Success(
productsSynced = successResult.productsSynced,
variationsSynced = successResult.variationsSynced,
syncDurationMs = syncDuration
)
}

suspend fun getProductCount(site: SiteModel): Int =
Expand Down
Loading