mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-23 19:26:17 +00:00
Fully rebuild FTS after a backup restore.
This commit is contained in:
@@ -9,6 +9,7 @@ import org.signal.core.util.SqlUtil
|
||||
import org.signal.core.util.ThreadUtil
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.signal.core.util.withinTransaction
|
||||
import org.thoughtcrime.securesms.jobs.RebuildMessageSearchIndexJob
|
||||
|
||||
/**
|
||||
* Contains all databases necessary for full-text search (FTS).
|
||||
@@ -222,7 +223,7 @@ class SearchTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops all tables and recreates them. Should only be done in extreme circumstances.
|
||||
* Drops all tables and recreates them.
|
||||
*/
|
||||
fun fullyResetTables() {
|
||||
Log.w(TAG, "[fullyResetTables] Dropping tables and triggers...")
|
||||
@@ -241,10 +242,9 @@ class SearchTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
|
||||
Log.w(TAG, "[fullyResetTables] Recreating triggers...")
|
||||
CREATE_TRIGGERS.forEach { writableDatabase.execSQL(it) }
|
||||
|
||||
Log.w(TAG, "[fullyResetTables] Rebuilding index...")
|
||||
rebuildIndex()
|
||||
RebuildMessageSearchIndexJob.enqueue()
|
||||
|
||||
Log.w(TAG, "[fullyResetTables] Done")
|
||||
Log.w(TAG, "[fullyResetTables] Done. Index will be rebuilt asynchronously)")
|
||||
}
|
||||
|
||||
private fun createFullTextSearchQuery(query: String): String {
|
||||
|
||||
@@ -272,8 +272,12 @@ open class SignalDatabase(private val context: Application, databaseSecret: Data
|
||||
return context.getDatabasePath(DATABASE_NAME)
|
||||
}
|
||||
|
||||
/**
|
||||
* After restoring a backup, we want to make sure that we run all of the onUpgrade logic necessary to bring the databases up to our current versions.
|
||||
* There's also some cleanup we wan tto do to remove any possibly bad/stale data.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun upgradeRestored(database: net.zetetic.database.sqlcipher.SQLiteDatabase) {
|
||||
fun runPostBackupRestoreTasks(database: net.zetetic.database.sqlcipher.SQLiteDatabase) {
|
||||
synchronized(SignalDatabase::class.java) {
|
||||
database.withinTransaction { db ->
|
||||
instance!!.onUpgrade(db, db.getVersion(), -1)
|
||||
@@ -281,6 +285,7 @@ open class SignalDatabase(private val context: Application, databaseSecret: Data
|
||||
instance!!.messageTable.deleteAbandonedMessages()
|
||||
instance!!.messageTable.trimEntriesForExpiredMessages()
|
||||
instance!!.reactionTable.deleteAbandonedReactions()
|
||||
instance!!.searchTable.fullyResetTables()
|
||||
instance!!.rawWritableDatabase.execSQL("DROP TABLE IF EXISTS key_value")
|
||||
instance!!.rawWritableDatabase.execSQL("DROP TABLE IF EXISTS megaphone")
|
||||
instance!!.rawWritableDatabase.execSQL("DROP TABLE IF EXISTS job_spec")
|
||||
|
||||
@@ -49,7 +49,7 @@ final class NewDeviceServerTask implements ServerTask {
|
||||
inputStream,
|
||||
passphrase);
|
||||
|
||||
SignalDatabase.upgradeRestored(database);
|
||||
SignalDatabase.runPostBackupRestoreTasks(database);
|
||||
NotificationChannels.getInstance().restoreContactNotificationChannels();
|
||||
|
||||
AppInitialization.onPostBackupRestore(context);
|
||||
|
||||
@@ -163,6 +163,7 @@ public final class JobManagerFactories {
|
||||
put(PushProcessEarlyMessagesJob.KEY, new PushProcessEarlyMessagesJob.Factory());
|
||||
put(PushProcessMessageJob.KEY, new PushProcessMessageJob.Factory());
|
||||
put(ReactionSendJob.KEY, new ReactionSendJob.Factory());
|
||||
put(RebuildMessageSearchIndexJob.KEY, new RebuildMessageSearchIndexJob.Factory());
|
||||
put(RefreshAttributesJob.KEY, new RefreshAttributesJob.Factory());
|
||||
put(RefreshKbsCredentialsJob.KEY, new RefreshKbsCredentialsJob.Factory());
|
||||
put(RefreshOwnProfileJob.KEY, new RefreshOwnProfileJob.Factory());
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
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.Job
|
||||
import java.lang.Exception
|
||||
|
||||
class RebuildMessageSearchIndexJob private constructor(params: Parameters) : BaseJob(params) {
|
||||
|
||||
companion object {
|
||||
private val TAG = Log.tag(RebuildMessageSearchIndexJob::class.java)
|
||||
|
||||
const val KEY = "RebuildMessageSearchIndexJob"
|
||||
|
||||
fun enqueue() {
|
||||
ApplicationDependencies.getJobManager().add(RebuildMessageSearchIndexJob())
|
||||
}
|
||||
}
|
||||
|
||||
private constructor() : this(
|
||||
Parameters.Builder()
|
||||
.setQueue("RebuildMessageSearchIndex")
|
||||
.build()
|
||||
)
|
||||
|
||||
override fun serialize(): ByteArray? = null
|
||||
|
||||
override fun getFactoryKey(): String = KEY
|
||||
|
||||
override fun onFailure() = Unit
|
||||
|
||||
override fun onRun() {
|
||||
SignalDatabase.messageSearch.rebuildIndex()
|
||||
}
|
||||
|
||||
override fun onShouldRetry(e: Exception): Boolean = false
|
||||
|
||||
class Factory : Job.Factory<RebuildMessageSearchIndexJob> {
|
||||
override fun create(parameters: Parameters, serializedData: ByteArray?): RebuildMessageSearchIndexJob {
|
||||
return RebuildMessageSearchIndexJob(parameters)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -291,7 +291,7 @@ public final class RestoreBackupFragment extends LoggingFragment {
|
||||
backup.getUri(),
|
||||
passphrase);
|
||||
|
||||
SignalDatabase.upgradeRestored(database);
|
||||
SignalDatabase.runPostBackupRestoreTasks(database);
|
||||
NotificationChannels.getInstance().restoreContactNotificationChannels();
|
||||
|
||||
enableBackups(context);
|
||||
|
||||
Reference in New Issue
Block a user