refactor: simplify epoch purge logic to always clear all synced history and findings upon database epoch update
This commit is contained in:
@@ -474,16 +474,10 @@ class MaintenanceRepository(
|
||||
val localEpoch = prefs.getInt("database_epoch", 0)
|
||||
|
||||
if (remoteEpoch > localEpoch) {
|
||||
android.util.Log.d("MaintenanceRepository", "Database epoch mudou de $localEpoch para $remoteEpoch. Executando purga seletiva de histórico e achados sincronizados...")
|
||||
val (epochActivities, _) = sheetsSyncService.fetchRemoteActivities()
|
||||
val activeOsList = epochActivities.map { it.numeroOs }.distinct()
|
||||
if (activeOsList.isNotEmpty()) {
|
||||
dao.deleteStaleSyncedHistory(activeOsList)
|
||||
dao.deleteStaleSyncedFindings(activeOsList)
|
||||
} else {
|
||||
dao.deleteAllSyncedHistory()
|
||||
dao.deleteAllSyncedFindings()
|
||||
}
|
||||
android.util.Log.d("MaintenanceRepository", "Database epoch mudou de $localEpoch para $remoteEpoch. Purgando todo o histórico e achados sincronizados locais para substituir completamente pela nova base remota...")
|
||||
// Completely clear previously synced history and findings so local database is replaced by the new remote database
|
||||
dao.deleteAllSyncedHistory()
|
||||
dao.deleteAllSyncedFindings()
|
||||
prefs.edit().putInt("database_epoch", remoteEpoch).apply()
|
||||
}
|
||||
|
||||
|
||||
@@ -636,11 +636,11 @@ class ExampleRobolectricTest {
|
||||
assertEquals(2, dao.getAllFindingsList().size)
|
||||
assertEquals(1, dao.getUnsyncedHistory().size)
|
||||
|
||||
// 5. Execute Epoch purge for active OS list ["OS-100"]
|
||||
dao.deleteStaleSyncedHistory(listOf("OS-100"))
|
||||
dao.deleteStaleSyncedFindings(listOf("OS-100"))
|
||||
// 5. Execute Epoch purge (deleteAllSyncedHistory and deleteAllSyncedFindings)
|
||||
dao.deleteAllSyncedHistory()
|
||||
dao.deleteAllSyncedFindings()
|
||||
|
||||
// 6. Verify that stale synced OS-999 entries were purged, while unsynced OS-100 entries were preserved
|
||||
// 6. Verify that ALL synced entries (OS-999) were purged, while unsynced entries (OS-100) were preserved
|
||||
val historyAfterPurge = dao.getAllHistoryList()
|
||||
assertEquals(1, historyAfterPurge.size)
|
||||
assertEquals("OS-100", historyAfterPurge.first().numeroOs)
|
||||
|
||||
Reference in New Issue
Block a user