Attempt to rebuild the FTS index in DB error handler.

This commit is contained in:
Greyson Parrelli 2025-01-10 13:13:29 -05:00
parent 54ecb0bb53
commit 123c282610
2 changed files with 18 additions and 10 deletions

View file

@ -258,6 +258,14 @@ class SearchTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
return true
}
/**
* Rebuilds the FTS index.
* Warning: This could be very expensive! (often seconds)
*/
fun rebuildIndex(db: SQLiteDatabase = writableDatabase.sqlCipherDatabase) {
db.execSQL("INSERT INTO $FTS_TABLE_NAME($FTS_TABLE_NAME) VALUES('rebuild')")
}
/**
* Drops all tables and recreates them.
*/

View file

@ -165,16 +165,16 @@ class SqlCipherErrorHandler(private val application: Application, private val da
}
private fun attemptToClearFullTextSearchIndex(db: SQLiteDatabase) {
// try {
// try {
// db.reopenReadWrite()
// } catch (e: Exception) {
// Log.w(TAG, "Failed to re-open as read-write!", e)
// }
// SignalDatabase.messageSearch.fullyResetTables(db, useTransaction = false)
// } catch (e: Throwable) {
// Log.w(TAG, "Failed to clear full text search index.", e)
// }
try {
try {
db.reopenReadWrite()
} catch (e: Exception) {
Log.w(TAG, "Failed to re-open as read-write!", e)
}
SignalDatabase.messageSearch.rebuildIndex(db)
} catch (e: Throwable) {
Log.w(TAG, "Failed to rebuild the full text search index.", e)
}
}
private sealed class DiagnosticResults(val logs: String) {