1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 19:52:17 -05:00

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).
This commit is contained in:
Romain Vimont (®om) 2012-05-30 12:45:37 +02:00
parent c7fd341eb8
commit fb36389d20

View File

@ -156,6 +156,8 @@ public class LocalStore extends Store implements Serializable {
AttachmentProvider.clear(mApplication); AttachmentProvider.clear(mApplication);
db.beginTransaction();
try {
try { try {
// schema version 29 was when we moved to incremental updates // 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 // 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!"); 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 // 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. // every time the user upgrades. it'll just cost them money and pain.
// try // try