diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/FastJobStorage.kt b/app/src/main/java/org/thoughtcrime/securesms/jobs/FastJobStorage.kt index 180fc72ae9..cb2decb58e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/FastJobStorage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/FastJobStorage.kt @@ -201,11 +201,11 @@ class FastJobStorage(private val jobDatabase: JobDatabase) : JobStorage { jobDatabase.updateJobAfterRetry(id, currentTime, runAttempt, nextBackoffInterval, serializedData) // Note: All other fields are accounted for in the min spec. We only need to update from disk if serialized data changes. - val cached = jobSpecCache[id] - if (cached != null && !cached.serializedData.contentEquals(serializedData)) { - jobDatabase.getJobSpec(id)?.let { - jobSpecCache[id] = it - } + jobSpecCache.computeIfPresent(id) { _, cached -> + if (cached.serializedData.contentEquals(serializedData)) + cached.copy(runAttempt = runAttempt) + else + jobDatabase.getJobSpec(id) } } diff --git a/app/src/test/java/org/thoughtcrime/securesms/jobs/FastJobStorageTest.kt b/app/src/test/java/org/thoughtcrime/securesms/jobs/FastJobStorageTest.kt index 4363b8d618..f4fdef4a3f 100644 --- a/app/src/test/java/org/thoughtcrime/securesms/jobs/FastJobStorageTest.kt +++ b/app/src/test/java/org/thoughtcrime/securesms/jobs/FastJobStorageTest.kt @@ -298,7 +298,7 @@ class FastJobStorageTest { @Test fun `updateJobAfterRetry - state updated`() { - val fullSpec = FullSpec(jobSpec(id = "1", factoryKey = "f1", isRunning = true), emptyList(), emptyList()) + val fullSpec = FullSpec(jobSpec(id = "1", factoryKey = "f1", isRunning = true, serializedData = "a".toByteArray()), emptyList(), emptyList()) val subject = FastJobStorage(mockDatabase(listOf(fullSpec))) subject.init() @@ -306,7 +306,7 @@ class FastJobStorageTest { subject.updateJobAfterRetry( id = "1", currentTime = 3, - runAttempt = 1, + runAttempt = 2, nextBackoffInterval = 10, serializedData = "a".toByteArray() ) @@ -315,7 +315,7 @@ class FastJobStorageTest { check(job != null) job.isRunning assertIs false job.lastRunAttemptTime assertIs 3 - job.runAttempt assertIs 1 + job.runAttempt assertIs 2 job.nextBackoffInterval assertIs 10 job.serializedData!!.toString(Charset.defaultCharset()) assertIs "a" }