mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 10:20:25 +01:00
Improve the performance of the migration by ~4x.
This commit is contained in:
@@ -112,9 +112,11 @@ public class ApplicationMigrations {
|
||||
static final int STORY_VIEWED_STATE = 68;
|
||||
static final int STORY_READ_STATE = 69;
|
||||
static final int THREAD_MESSAGE_SCHEMA_CHANGE = 70;
|
||||
static final int SMS_MMS_MERGE = 71;
|
||||
static final int REBUILD_MESSAGE_FTS_INDEX = 72;
|
||||
}
|
||||
|
||||
public static final int CURRENT_VERSION = 70;
|
||||
public static final int CURRENT_VERSION = 72;
|
||||
|
||||
/**
|
||||
* This *must* be called after the {@link JobManager} has been instantiated, but *before* the call
|
||||
@@ -496,6 +498,14 @@ public class ApplicationMigrations {
|
||||
jobs.put(Version.THREAD_MESSAGE_SCHEMA_CHANGE, new DatabaseMigrationJob());
|
||||
}
|
||||
|
||||
if (lastSeenVersion < Version.SMS_MMS_MERGE) {
|
||||
jobs.put(Version.SMS_MMS_MERGE, new DatabaseMigrationJob());
|
||||
}
|
||||
|
||||
if (lastSeenVersion < Version.REBUILD_MESSAGE_FTS_INDEX) {
|
||||
jobs.put(Version.REBUILD_MESSAGE_FTS_INDEX, new RebuildMessageSearchIndexMigrationJob());
|
||||
}
|
||||
|
||||
return jobs;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.thoughtcrime.securesms.migrations
|
||||
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
import org.thoughtcrime.securesms.jobmanager.Data
|
||||
import org.thoughtcrime.securesms.jobmanager.Job
|
||||
|
||||
/**
|
||||
* Rebuilds the full-text search index for the messages table.
|
||||
*/
|
||||
internal class RebuildMessageSearchIndexMigrationJob(
|
||||
parameters: Parameters = Parameters.Builder().build()
|
||||
) : MigrationJob(parameters) {
|
||||
|
||||
companion object {
|
||||
val TAG = Log.tag(RebuildMessageSearchIndexMigrationJob::class.java)
|
||||
const val KEY = "RebuildMessageSearchIndexMigrationJob"
|
||||
}
|
||||
|
||||
override fun getFactoryKey(): String = KEY
|
||||
|
||||
override fun isUiBlocking(): Boolean = false
|
||||
|
||||
override fun performMigration() {
|
||||
val startTime = System.currentTimeMillis()
|
||||
SignalDatabase.messageSearch.rebuildIndex()
|
||||
Log.d(TAG, "It took ${System.currentTimeMillis() - startTime} ms to rebuild the search index.")
|
||||
}
|
||||
|
||||
override fun shouldRetry(e: Exception): Boolean = false
|
||||
|
||||
class Factory : Job.Factory<RebuildMessageSearchIndexMigrationJob> {
|
||||
override fun create(parameters: Parameters, data: Data): RebuildMessageSearchIndexMigrationJob {
|
||||
return RebuildMessageSearchIndexMigrationJob(parameters)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user