From 0e8c0167137f19acb909294945c947b550c183f3 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 20 Jan 2021 18:22:58 +0100 Subject: [PATCH] Cleanup/transaction --- .../java/eu/faircode/email/WorkerCleanup.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/WorkerCleanup.java b/app/src/main/java/eu/faircode/email/WorkerCleanup.java index c82bcdd2ff..11c8d0cbb5 100644 --- a/app/src/main/java/eu/faircode/email/WorkerCleanup.java +++ b/app/src/main/java/eu/faircode/email/WorkerCleanup.java @@ -295,16 +295,28 @@ public class WorkerCleanup extends Worker { } Log.i("Cleanup contacts"); - int contacts = db.contact().deleteContacts(now - KEEP_CONTACTS_DURATION); - Log.i("Deleted contacts=" + contacts); + try { + db.beginTransaction(); + int contacts = db.contact().deleteContacts(now - KEEP_CONTACTS_DURATION); + db.setTransactionSuccessful(); + Log.i("Deleted contacts=" + contacts); + } finally { + db.endTransaction(); + } Log.i("Cleanup log"); long before = now - KEEP_LOG_DURATION; while (true) { - int logs = db.log().deleteLogs(before, LOG_DELETE_BATCH_SIZE); - Log.i("Deleted logs=" + logs + " before=" + new Date(before)); - if (logs < LOG_DELETE_BATCH_SIZE) - break; + try { + db.beginTransaction(); + int logs = db.log().deleteLogs(before, LOG_DELETE_BATCH_SIZE); + db.setTransactionSuccessful(); + Log.i("Deleted logs=" + logs + " before=" + new Date(before)); + if (logs < LOG_DELETE_BATCH_SIZE) + break; + } finally { + db.endTransaction(); + } } if (BuildConfig.DEBUG) {