From fb36389d20c0bc2b22f74cf3457f64879af6c36e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Vimont=20=28=C2=AEom=29?= Date: Wed, 30 May 2012 12:45:37 +0200 Subject: [PATCH] Create database in a transaction (for performance) On my emulator, it takes 70ms instead of 250ms. On a very specific hardware, it takes 0,5s instead of 4,1s. I willingly did not indent the code between my try/catch (for the patch to be readable). --- src/com/fsck/k9/mail/store/LocalStore.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index d7417c2e1..b93304ea2 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -156,6 +156,8 @@ public class LocalStore extends Store implements Serializable { AttachmentProvider.clear(mApplication); + db.beginTransaction(); + try { try { // schema version 29 was when we moved to incremental updates // in the case of a new db or a < v29 db, we blow away and start from scratch @@ -385,6 +387,11 @@ public class LocalStore extends Store implements Serializable { throw new Error("Database upgrade failed!"); } + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + // Unless we're blowing away the whole data store, there's no reason to prune attachments // every time the user upgrades. it'll just cost them money and pain. // try