Improve routine around bulk attachment deletion.

This commit is contained in:
Cody Henthorne
2021-07-15 13:32:29 -04:00
committed by Greyson Parrelli
parent b04ca202f6
commit f65f4704c9
6 changed files with 83 additions and 8 deletions

View File

@@ -77,9 +77,10 @@ public class ApplicationMigrations {
static final int SENDER_KEY = 35;
static final int SENDER_KEY_2 = 36;
static final int DB_AUTOINCREMENT = 37;
static final int ATTACHMENT_CLEANUP = 38;
}
public static final int CURRENT_VERSION = 37;
public static final int CURRENT_VERSION = 38;
/**
* This *must* be called after the {@link JobManager} has been instantiated, but *before* the call
@@ -322,7 +323,7 @@ public class ApplicationMigrations {
}
if (lastSeenVersion < Version.APPLY_UNIVERSAL_EXPIRE) {
jobs.put(Version.SMS_STORAGE_SYNC, new ApplyUnknownFieldsToSelfMigrationJob());
jobs.put(Version.APPLY_UNIVERSAL_EXPIRE, new ApplyUnknownFieldsToSelfMigrationJob());
}
if (lastSeenVersion < Version.SENDER_KEY) {
@@ -337,6 +338,10 @@ public class ApplicationMigrations {
jobs.put(Version.DB_AUTOINCREMENT, new DatabaseMigrationJob());
}
if (lastSeenVersion < Version.ATTACHMENT_CLEANUP) {
jobs.put(Version.ATTACHMENT_CLEANUP, new AttachmentCleanupMigrationJob());
}
return jobs;
}

View File

@@ -0,0 +1,54 @@
package org.thoughtcrime.securesms.migrations;
import androidx.annotation.NonNull;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.jobmanager.Data;
import org.thoughtcrime.securesms.jobmanager.Job;
/**
* Check for abandoned attachments and delete them.
*/
public class AttachmentCleanupMigrationJob extends MigrationJob {
private static final String TAG = Log.tag(AttachmentCleanupMigrationJob.class);
public static final String KEY = "AttachmentCleanupMigrationJob";
AttachmentCleanupMigrationJob() {
this(new Parameters.Builder().build());
}
private AttachmentCleanupMigrationJob(@NonNull Parameters parameters) {
super(parameters);
}
@Override
public boolean isUiBlocking() {
return false;
}
@Override
public @NonNull String getFactoryKey() {
return KEY;
}
@Override
public void performMigration() {
int deletes = DatabaseFactory.getAttachmentDatabase(context).deleteAbandonedAttachmentFiles();
Log.i(TAG, "Deleted " + deletes + " abandoned attachments.");
}
@Override
boolean shouldRetry(@NonNull Exception e) {
return false;
}
public static class Factory implements Job.Factory<AttachmentCleanupMigrationJob> {
@Override
public @NonNull AttachmentCleanupMigrationJob create(@NonNull Parameters parameters, @NonNull Data data) {
return new AttachmentCleanupMigrationJob(parameters);
}
}
}