Clean up dangling wallpapers.

This commit is contained in:
Greyson Parrelli
2024-10-09 09:58:00 -04:00
parent 3381d20bd7
commit 95d8abfb46
5 changed files with 82 additions and 1 deletions

View File

@@ -2073,6 +2073,36 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
.run()
}
/**
* A follow up to [migrateWallpaperUri]. This clears out any remaining wallpapers using the old URI scheme, which implies
* that they were not migrated, which would only happen if they could not be read or were no longer found (the latter being
* more common, as this would happen after restoring a backup).
*/
fun clearMissingFileWallpapersPostMigration(): Int {
return writableDatabase
.update(TABLE_NAME)
.values(
WALLPAPER to null,
WALLPAPER_URI to null
)
.where("$WALLPAPER_URI LIKE ?", "%wallpaper%")
.run()
}
/**
* Our current backup system does not backup file wallpapers. So we should clear them post-restore to avoid any weird UI issues.
*/
fun clearFileWallpapersPostBackupRestore() {
writableDatabase
.update(TABLE_NAME)
.values(
WALLPAPER to null,
WALLPAPER_URI to null
)
.where("$WALLPAPER_URI NOT NULL")
.run()
}
fun getPhoneNumberDiscoverability(id: RecipientId): PhoneNumberDiscoverableState? {
return readableDatabase
.select(PHONE_NUMBER_DISCOVERABLE)

View File

@@ -300,6 +300,7 @@ open class SignalDatabase(private val context: Application, databaseSecret: Data
instance!!.messageTable.trimEntriesForExpiredMessages()
instance!!.reactionTable.deleteAbandonedReactions()
instance!!.searchTable.fullyResetTables(useTransaction = false)
instance!!.recipientTable.clearFileWallpapersPostBackupRestore()
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")