mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 16:49:40 +01: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")
|
||||
|
||||
Reference in New Issue
Block a user