Skip to content

Commit

Permalink
Fix possible crash during backup restore.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Feb 21, 2023
1 parent ba8ea3b commit ab9057c
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.thoughtcrime.securesms.jobs

import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.database.SignalDatabase
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
import org.thoughtcrime.securesms.jobmanager.Data
import org.thoughtcrime.securesms.jobmanager.Job
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.transport.RetryLaterException
import java.lang.Exception
import kotlin.time.Duration.Companion.seconds
Expand All @@ -16,6 +18,8 @@ class OptimizeMessageSearchIndexJob private constructor(parameters: Parameters)
companion object {
const val KEY = "OptimizeMessageSearchIndexJob"

private val TAG = Log.tag(OptimizeMessageSearchIndexJob::class.java)

@JvmStatic
fun enqueue() {
ApplicationDependencies.getJobManager().add(OptimizeMessageSearchIndexJob())
Expand All @@ -37,6 +41,11 @@ class OptimizeMessageSearchIndexJob private constructor(parameters: Parameters)
override fun getNextRunAttemptBackoff(pastAttemptCount: Int, exception: Exception): Long = 30.seconds.inWholeMilliseconds

override fun onRun() {
if (!SignalStore.registrationValues().isRegistrationComplete || SignalStore.account().aci == null) {
Log.w(TAG, "Registration not finished yet! Skipping.")
return
}

val success = SignalDatabase.messageSearch.optimizeIndex(5.seconds.inWholeMilliseconds)

if (!success) {
Expand Down

0 comments on commit ab9057c

Please sign in to comment.