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)
|
val localEpoch = prefs.getInt("database_epoch", 0)
|
||||||
|
|
||||||
if (remoteEpoch > localEpoch) {
|
if (remoteEpoch > localEpoch) {
|
||||||
android.util.Log.d("MaintenanceRepository", "Database epoch mudou de $localEpoch para $remoteEpoch. Executando purga seletiva de histórico e achados sincronizados...")
|
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...")
|
||||||
val (epochActivities, _) = sheetsSyncService.fetchRemoteActivities()
|
// Completely clear previously synced history and findings so local database is replaced by the new remote database
|
||||||
val activeOsList = epochActivities.map { it.numeroOs }.distinct()
|
dao.deleteAllSyncedHistory()
|
||||||
if (activeOsList.isNotEmpty()) {
|
dao.deleteAllSyncedFindings()
|
||||||
dao.deleteStaleSyncedHistory(activeOsList)
|
|
||||||
dao.deleteStaleSyncedFindings(activeOsList)
|
|
||||||
} else {
|
|
||||||
dao.deleteAllSyncedHistory()
|
|
||||||
dao.deleteAllSyncedFindings()
|
|
||||||
}
|
|
||||||
prefs.edit().putInt("database_epoch", remoteEpoch).apply()
|
prefs.edit().putInt("database_epoch", remoteEpoch).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -636,11 +636,11 @@ class ExampleRobolectricTest {
|
|||||||
assertEquals(2, dao.getAllFindingsList().size)
|
assertEquals(2, dao.getAllFindingsList().size)
|
||||||
assertEquals(1, dao.getUnsyncedHistory().size)
|
assertEquals(1, dao.getUnsyncedHistory().size)
|
||||||
|
|
||||||
// 5. Execute Epoch purge for active OS list ["OS-100"]
|
// 5. Execute Epoch purge (deleteAllSyncedHistory and deleteAllSyncedFindings)
|
||||||
dao.deleteStaleSyncedHistory(listOf("OS-100"))
|
dao.deleteAllSyncedHistory()
|
||||||
dao.deleteStaleSyncedFindings(listOf("OS-100"))
|
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()
|
val historyAfterPurge = dao.getAllHistoryList()
|
||||||
assertEquals(1, historyAfterPurge.size)
|
assertEquals(1, historyAfterPurge.size)
|
||||||
assertEquals("OS-100", historyAfterPurge.first().numeroOs)
|
assertEquals("OS-100", historyAfterPurge.first().numeroOs)
|
||||||
|
|||||||
Reference in New Issue
Block a user