Skip to content

Commit 743a057

Browse files
committed
Save Incident claim thresholds of cached Incidents only
1 parent 5e0b66f commit 743a057

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

core/data/src/main/java/com/crisiscleanup/core/data/repository/IncidentClaimThresholdRepository.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.crisiscleanup.core.database.dao.IncidentDao
1010
import com.crisiscleanup.core.database.dao.IncidentDaoPlus
1111
import com.crisiscleanup.core.datastore.AccountInfoDataSource
1212
import com.crisiscleanup.core.model.data.IncidentClaimThreshold
13+
import com.crisiscleanup.core.model.data.IncidentsData
1314
import kotlinx.coroutines.flow.first
1415
import java.util.concurrent.ConcurrentHashMap
1516
import javax.inject.Inject
@@ -48,7 +49,13 @@ class CrisisCleanupIncidentClaimThresholdRepository @Inject constructor(
4849
incidentThresholds: List<IncidentClaimThreshold>,
4950
) {
5051
try {
51-
incidentDaoPlus.saveIncidentThresholds(accountId, incidentThresholds)
52+
val incidentsData = incidentSelector.data.value
53+
val incidentIds = (incidentsData as? IncidentsData.Incidents)?.incidents
54+
?.map { it.id }
55+
?.toSet()
56+
?: emptySet()
57+
val thresholds = incidentThresholds.filter { incidentIds.contains(it.incidentId) }
58+
incidentDaoPlus.saveIncidentThresholds(accountId, thresholds)
5259
} catch (e: Exception) {
5360
logger.logException(e)
5461
}

0 commit comments

Comments
 (0)