From 4a8d93b572f33a6e43e009705dda333e1eba1ab0 Mon Sep 17 00:00:00 2001 From: Philip Whitehouse Date: Tue, 31 Jan 2017 12:51:47 +0000 Subject: [PATCH] Add missing indexes in new database migration step --- .../com/fsck/k9/mailstore/LocalStore.java | 2 +- .../mailstore/migrations/MigrationTo59.java | 41 +++++++++++++++++++ .../k9/mailstore/migrations/Migrations.java | 2 + 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 k9mail/src/main/java/com/fsck/k9/mailstore/migrations/MigrationTo59.java diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalStore.java b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalStore.java index 211e361b8..6ad7e47b9 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalStore.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalStore.java @@ -153,7 +153,7 @@ public class LocalStore extends Store implements Serializable { */ private static final int THREAD_FLAG_UPDATE_BATCH_SIZE = 500; - public static final int DB_VERSION = 58; + public static final int DB_VERSION = 59; public static String getColumnNameForFlag(Flag flag) { diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/migrations/MigrationTo59.java b/k9mail/src/main/java/com/fsck/k9/mailstore/migrations/MigrationTo59.java new file mode 100644 index 000000000..5a00852c6 --- /dev/null +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/migrations/MigrationTo59.java @@ -0,0 +1,41 @@ +package com.fsck.k9.mailstore.migrations; + + +import android.database.sqlite.SQLiteDatabase; + + +class MigrationTo59 { + static void addMissingIndexes(SQLiteDatabase db) { + addMessageCompositeIndex(db); + addMessageEmptyIndex(db); + addMessageFlaggedIndex(db); + addMessageFolderIdDeletedDateIndex(db); + addMessageReadIndex(db); + addMessageUidIndex(db); + addMessageReadIndex(db); + } + + private static void addMessageCompositeIndex(SQLiteDatabase db) { + db.execSQL("CREATE INDEX IF NOT EXISTS msg_composite ON messages (deleted, empty,folder_id,flagged,read)"); + } + + private static void addMessageEmptyIndex(SQLiteDatabase db) { + db.execSQL("CREATE INDEX IF NOT EXISTS msg_empty ON messages (empty)"); + } + + private static void addMessageFlaggedIndex(SQLiteDatabase db) { + db.execSQL("CREATE INDEX IF NOT EXISTS msg_flagged ON messages (flagged)"); + } + + private static void addMessageFolderIdDeletedDateIndex(SQLiteDatabase db) { + db.execSQL("CREATE INDEX IF NOT EXISTS msg_folder_id_deleted_date ON messages (folder_id,deleted,internal_date)"); + } + + private static void addMessageReadIndex(SQLiteDatabase db) { + db.execSQL("CREATE INDEX IF NOT EXISTS msg_read ON messages (read)"); + } + + private static void addMessageUidIndex(SQLiteDatabase db) { + db.execSQL("CREATE INDEX IF NOT EXISTS msg_uid ON messages (uid, folder_id)"); + } +} diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/migrations/Migrations.java b/k9mail/src/main/java/com/fsck/k9/mailstore/migrations/Migrations.java index 7de45c8d9..ad913445b 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/migrations/Migrations.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/migrations/Migrations.java @@ -71,6 +71,8 @@ public class Migrations { case 57: MigrationTo58.cleanUpOrphanedData(db); MigrationTo58.createDeleteMessageTrigger(db); + case 58: + MigrationTo59.addMissingIndexes(db); } } }