From 0cb28c5f0a1a87eddfa35e1e7a2683cba217b169 Mon Sep 17 00:00:00 2001 From: Davide Ferrari Date: Mon, 5 Jan 2026 10:10:55 +0100 Subject: [PATCH] feat(stats): add per-item progress logging for sync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Logs now show each drive/charge as it's synced with remaining count: - "Drive 123 synced (45 remaining)" - "Charge 456 synced (12 remaining)" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../com/matedroid/data/sync/SyncRepository.kt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/matedroid/data/sync/SyncRepository.kt b/app/src/main/java/com/matedroid/data/sync/SyncRepository.kt index dd896a0..659a658 100644 --- a/app/src/main/java/com/matedroid/data/sync/SyncRepository.kt +++ b/app/src/main/java/com/matedroid/data/sync/SyncRepository.kt @@ -126,17 +126,20 @@ class SyncRepository @Inject constructor( */ suspend fun syncDriveDetails(carId: Int): Boolean { val unprocessedIds = driveSummaryDao.getUnprocessedDriveIds(carId, SchemaVersion.CURRENT) - log("Processing ${unprocessedIds.size} drive details for car $carId") + val total = unprocessedIds.size + log("Processing $total drive details for car $carId") - for (driveId in unprocessedIds) { + unprocessedIds.forEachIndexed { index, driveId -> + val remaining = total - index - 1 when (val result = teslamateRepository.getDriveDetail(carId, driveId)) { is ApiResult.Success -> { val aggregate = computeDriveAggregate(carId, result.data) aggregateDao.upsertDriveAggregate(aggregate) syncManager.updateDriveDetailProgress(carId, driveId) + log("Drive $driveId synced ($remaining remaining)") } is ApiResult.Error -> { - logError("Failed to fetch drive $driveId: ${result.message}") + logError("Drive $driveId failed: ${result.message} ($remaining remaining)") // Continue with next drive instead of failing entirely } } @@ -154,17 +157,20 @@ class SyncRepository @Inject constructor( */ suspend fun syncChargeDetails(carId: Int): Boolean { val unprocessedIds = chargeSummaryDao.getUnprocessedChargeIds(carId, SchemaVersion.CURRENT) - log("Processing ${unprocessedIds.size} charge details for car $carId") + val total = unprocessedIds.size + log("Processing $total charge details for car $carId") - for (chargeId in unprocessedIds) { + unprocessedIds.forEachIndexed { index, chargeId -> + val remaining = total - index - 1 when (val result = teslamateRepository.getChargeDetail(carId, chargeId)) { is ApiResult.Success -> { val aggregate = computeChargeAggregate(carId, result.data) aggregateDao.upsertChargeAggregate(aggregate) syncManager.updateChargeDetailProgress(carId, chargeId) + log("Charge $chargeId synced ($remaining remaining)") } is ApiResult.Error -> { - logError("Failed to fetch charge $chargeId: ${result.message}") + logError("Charge $chargeId failed: ${result.message} ($remaining remaining)") // Continue with next charge instead of failing entirely } }