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

@@ -159,9 +159,10 @@ public class ApplicationMigrations {
static final int WALLPAPER_MIGRATION = 115;
static final int BACKFILL_DIGESTS_V3 = 116;
static final int SVR2_ENCLAVE_UPDATE_2 = 117;
static final int WALLPAPER_MIGRATION_CLEANUP = 118;
}
public static final int CURRENT_VERSION = 117;
public static final int CURRENT_VERSION = 118;
/**
* This *must* be called after the {@link JobManager} has been instantiated, but *before* the call
@@ -728,6 +729,10 @@ public class ApplicationMigrations {
jobs.put(Version.SVR2_ENCLAVE_UPDATE_2, new Svr2MirrorMigrationJob());
}
if (lastSeenVersion < Version.WALLPAPER_MIGRATION_CLEANUP) {
jobs.put(Version.WALLPAPER_MIGRATION_CLEANUP, new WallpaperCleanupMigrationJob());
}
return jobs;
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.thoughtcrime.securesms.migrations
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.database.SignalDatabase
import org.thoughtcrime.securesms.jobmanager.Job
/**
* [WallpaperStorageMigrationJob] left some stragglers in the DB for wallpapers that couldn't be found on disk. This cleans those up.
* It'd be great if we could do this in a database migration, but unfortunately we need to ensure that the aforementioned
* [WallpaperStorageMigrationJob] finished.
*/
internal class WallpaperCleanupMigrationJob(parameters: Parameters = Parameters.Builder().build()) : MigrationJob(parameters) {
companion object {
private val TAG = Log.tag(WallpaperCleanupMigrationJob::class.java)
const val KEY = "WallpaperCleanupMigrationJob"
}
override fun getFactoryKey(): String = KEY
override fun isUiBlocking(): Boolean = false
override fun performMigration() {
val count = SignalDatabase.recipients.clearMissingFileWallpapersPostMigration()
if (count > 0) {
Log.w(TAG, "There were $count legacy wallpapers that needed to be cleared.")
} else {
Log.i(TAG, "No legacy wallpapers needed to be cleared.")
}
}
override fun shouldRetry(e: Exception): Boolean = false
class Factory : Job.Factory<WallpaperCleanupMigrationJob> {
override fun create(parameters: Parameters, serializedData: ByteArray?): WallpaperCleanupMigrationJob {
return WallpaperCleanupMigrationJob(parameters)
}
}
}