mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 01:58:34 +00:00
Fix possible threading issues with attachment cleanup.
The way things were ordered, it was possible for us to create an attachment file, but have it 'cleaned up' before we were able to link it to an attachment row.
This commit is contained in:
parent
864a1d5e93
commit
e3ce18fa3e
@ -437,7 +437,7 @@ public class AttachmentDatabase extends Database {
|
|||||||
public void trimAllAbandonedAttachments() {
|
public void trimAllAbandonedAttachments() {
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
String selectAllMmsIds = "SELECT " + MmsDatabase.ID + " FROM " + MmsDatabase.TABLE_NAME;
|
String selectAllMmsIds = "SELECT " + MmsDatabase.ID + " FROM " + MmsDatabase.TABLE_NAME;
|
||||||
String selectDataInUse = "SELECT DISTINCT " + DATA + " FROM " + TABLE_NAME + " WHERE " + QUOTE + " = 0 AND " + MMS_ID + " IN (" + selectAllMmsIds + ")";
|
String selectDataInUse = "SELECT DISTINCT " + DATA + " FROM " + TABLE_NAME + " WHERE " + QUOTE + " = 0 AND (" + MMS_ID + " IN (" + selectAllMmsIds + ") OR " + MMS_ID + " = " + PREUPLOAD_MESSAGE_ID + ")";
|
||||||
String where = MMS_ID + " NOT IN (" + selectAllMmsIds + ") AND " + DATA + " NOT IN (" + selectDataInUse + ")";
|
String where = MMS_ID + " NOT IN (" + selectAllMmsIds + ") AND " + DATA + " NOT IN (" + selectDataInUse + ")";
|
||||||
|
|
||||||
db.delete(TABLE_NAME, where, null);
|
db.delete(TABLE_NAME, where, null);
|
||||||
@ -1209,8 +1209,10 @@ public class AttachmentDatabase extends Database {
|
|||||||
throws MmsException
|
throws MmsException
|
||||||
{
|
{
|
||||||
Log.d(TAG, "Inserting attachment for mms id: " + mmsId);
|
Log.d(TAG, "Inserting attachment for mms id: " + mmsId);
|
||||||
|
|
||||||
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
||||||
|
|
||||||
|
database.beginTransaction();
|
||||||
|
try {
|
||||||
DataInfo dataInfo = null;
|
DataInfo dataInfo = null;
|
||||||
long uniqueId = System.currentTimeMillis();
|
long uniqueId = System.currentTimeMillis();
|
||||||
|
|
||||||
@ -1289,7 +1291,12 @@ public class AttachmentDatabase extends Database {
|
|||||||
notifyStickerPackListeners();
|
notifyStickerPackListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
database.setTransactionSuccessful();
|
||||||
|
|
||||||
return attachmentId;
|
return attachmentId;
|
||||||
|
} finally {
|
||||||
|
database.endTransaction();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private @Nullable DatabaseAttachment findTemplateAttachment(@NonNull String dataHash) {
|
private @Nullable DatabaseAttachment findTemplateAttachment(@NonNull String dataHash) {
|
||||||
|
@ -283,12 +283,12 @@ public class ThreadDatabase extends Database {
|
|||||||
mmsSmsDatabase.deleteAbandonedMessages();
|
mmsSmsDatabase.deleteAbandonedMessages();
|
||||||
attachmentDatabase.trimAllAbandonedAttachments();
|
attachmentDatabase.trimAllAbandonedAttachments();
|
||||||
groupReceiptDatabase.deleteAbandonedRows();
|
groupReceiptDatabase.deleteAbandonedRows();
|
||||||
|
attachmentDatabase.deleteAbandonedAttachmentFiles();
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
} finally {
|
} finally {
|
||||||
db.endTransaction();
|
db.endTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
attachmentDatabase.deleteAbandonedAttachmentFiles();
|
|
||||||
|
|
||||||
notifyAttachmentListeners();
|
notifyAttachmentListeners();
|
||||||
notifyStickerListeners();
|
notifyStickerListeners();
|
||||||
@ -312,12 +312,12 @@ public class ThreadDatabase extends Database {
|
|||||||
mmsSmsDatabase.deleteAbandonedMessages();
|
mmsSmsDatabase.deleteAbandonedMessages();
|
||||||
attachmentDatabase.trimAllAbandonedAttachments();
|
attachmentDatabase.trimAllAbandonedAttachments();
|
||||||
groupReceiptDatabase.deleteAbandonedRows();
|
groupReceiptDatabase.deleteAbandonedRows();
|
||||||
|
attachmentDatabase.deleteAbandonedAttachmentFiles();
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
} finally {
|
} finally {
|
||||||
db.endTransaction();
|
db.endTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
attachmentDatabase.deleteAbandonedAttachmentFiles();
|
|
||||||
|
|
||||||
notifyAttachmentListeners();
|
notifyAttachmentListeners();
|
||||||
notifyStickerListeners();
|
notifyStickerListeners();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user