Fix possible de-duping issues.

- Clean bad hashes from earlier release.
- Fix file equality comparison.
- Given our new de-duping, we don't want to run into a situation where two
simultaneous compressions could be happening on the same image.
This commit is contained in:
Greyson Parrelli 2019-10-23 16:16:13 -07:00
parent 23d478191f
commit 4260a8436b
3 changed files with 10 additions and 3 deletions

View file

@ -819,7 +819,7 @@ public class AttachmentDatabase extends Database {
Optional<DataInfo> sharedDataInfo = findDuplicateDataFileInfo(database, hash, attachmentId); Optional<DataInfo> sharedDataInfo = findDuplicateDataFileInfo(database, hash, attachmentId);
if (sharedDataInfo.isPresent()) { if (sharedDataInfo.isPresent()) {
Log.i(TAG, "[setAttachmentData] Duplicate data file found! " + sharedDataInfo.get().file.getAbsolutePath()); Log.i(TAG, "[setAttachmentData] Duplicate data file found! " + sharedDataInfo.get().file.getAbsolutePath());
if (sharedDataInfo.get().file != destination && destination.delete()) { if (!destination.equals(sharedDataInfo.get().file) && destination.delete()) {
Log.i(TAG, "[setAttachmentData] Deleted original file. " + destination); Log.i(TAG, "[setAttachmentData] Deleted original file. " + destination);
} }
return sharedDataInfo.get(); return sharedDataInfo.get();

View file

@ -87,8 +87,9 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
private static final int BLUR_HASH = 30; private static final int BLUR_HASH = 30;
private static final int MMS_RECIPIENT_CLEANUP_2 = 31; private static final int MMS_RECIPIENT_CLEANUP_2 = 31;
private static final int ATTACHMENT_TRANSFORM_PROPERTIES = 32; private static final int ATTACHMENT_TRANSFORM_PROPERTIES = 32;
private static final int ATTACHMENT_CLEAR_HASHES = 33;
private static final int DATABASE_VERSION = 32; private static final int DATABASE_VERSION = 33;
private static final String DATABASE_NAME = "signal.db"; private static final String DATABASE_NAME = "signal.db";
private final Context context; private final Context context;
@ -602,6 +603,10 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
db.execSQL("ALTER TABLE part ADD COLUMN transform_properties TEXT DEFAULT NULL"); db.execSQL("ALTER TABLE part ADD COLUMN transform_properties TEXT DEFAULT NULL");
} }
if (oldVersion < ATTACHMENT_CLEAR_HASHES) {
db.execSQL("UPDATE part SET data_hash = null");
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
db.endTransaction(); db.endTransaction();

View file

@ -74,7 +74,7 @@ public final class AttachmentCompressionJob extends BaseJob {
.addConstraint(NetworkConstraint.KEY) .addConstraint(NetworkConstraint.KEY)
.setLifespan(TimeUnit.DAYS.toMillis(1)) .setLifespan(TimeUnit.DAYS.toMillis(1))
.setMaxAttempts(Parameters.UNLIMITED) .setMaxAttempts(Parameters.UNLIMITED)
.setQueue(isVideoTranscode ? "VIDEO_TRANSCODE" : null) .setQueue(isVideoTranscode ? "VIDEO_TRANSCODE" : "GENERIC_TRANSCODE")
.build(), .build(),
attachmentId, attachmentId,
mms, mms,
@ -108,6 +108,8 @@ public final class AttachmentCompressionJob extends BaseJob {
@Override @Override
public void onRun() throws Exception { public void onRun() throws Exception {
Log.d(TAG, "Running for: " + attachmentId);
AttachmentDatabase database = DatabaseFactory.getAttachmentDatabase(context); AttachmentDatabase database = DatabaseFactory.getAttachmentDatabase(context);
DatabaseAttachment databaseAttachment = database.getAttachment(attachmentId); DatabaseAttachment databaseAttachment = database.getAttachment(attachmentId);