From 26c4d746d206a57687e90d5778fe2f090e868408 Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Tue, 28 Apr 2015 00:16:37 -0500 Subject: [PATCH] make part and mms insertion a single transaction fixes #3051 closes #3059 // FREEBIE --- .../securesms/database/MmsDatabase.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/org/thoughtcrime/securesms/database/MmsDatabase.java b/src/org/thoughtcrime/securesms/database/MmsDatabase.java index 26192f1c00..ec504b9730 100644 --- a/src/org/thoughtcrime/securesms/database/MmsDatabase.java +++ b/src/org/thoughtcrime/securesms/database/MmsDatabase.java @@ -749,15 +749,21 @@ public class MmsDatabase extends MessagingDatabase { contentValues.put(PART_COUNT, PartParser.getSupportedMediaPartCount(body)); - long messageId = db.insert(TABLE_NAME, null, contentValues); + db.beginTransaction(); + try { + long messageId = db.insert(TABLE_NAME, null, contentValues); - addressDatabase.insertAddressesForId(messageId, headers); - partsDatabase.insertParts(masterSecret, messageId, body); + addressDatabase.insertAddressesForId(messageId, headers); + partsDatabase.insertParts(masterSecret, messageId, body); - notifyConversationListeners(contentValues.getAsLong(THREAD_ID)); - DatabaseFactory.getThreadDatabase(context).update(contentValues.getAsLong(THREAD_ID)); + notifyConversationListeners(contentValues.getAsLong(THREAD_ID)); + DatabaseFactory.getThreadDatabase(context).update(contentValues.getAsLong(THREAD_ID)); + db.setTransactionSuccessful(); + return messageId; + } finally { + db.endTransaction(); + } - return messageId; } public boolean delete(long messageId) {