From f3e55347970bbe6929556492494218f7fae9ee3d Mon Sep 17 00:00:00 2001 From: cketti Date: Sun, 8 Jan 2017 08:50:10 +0100 Subject: [PATCH] Clean up FTS table on update --- .../main/java/com/fsck/k9/mailstore/LocalStore.java | 2 +- .../fsck/k9/mailstore/migrations/MigrationTo56.java | 11 +++++++++++ .../com/fsck/k9/mailstore/migrations/Migrations.java | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 k9mail/src/main/java/com/fsck/k9/mailstore/migrations/MigrationTo56.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 d763754b3..5f669ae81 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 = 55; + public static final int DB_VERSION = 56; public static String getColumnNameForFlag(Flag flag) { diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/migrations/MigrationTo56.java b/k9mail/src/main/java/com/fsck/k9/mailstore/migrations/MigrationTo56.java new file mode 100644 index 000000000..b8ddd9b18 --- /dev/null +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/migrations/MigrationTo56.java @@ -0,0 +1,11 @@ +package com.fsck.k9.mailstore.migrations; + + +import android.database.sqlite.SQLiteDatabase; + + +class MigrationTo56 { + static void cleanUpFtsTable(SQLiteDatabase db) { + db.execSQL("DELETE FROM messages_fulltext WHERE docid NOT IN (SELECT id FROM messages WHERE deleted = 0)"); + } +} 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 4c8aec597..7666b5256 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 @@ -64,6 +64,8 @@ public class Migrations { MigrationTo54.addPreviewTypeColumn(db); case 54: MigrationTo55.createFtsSearchTable(db, migrationsHelper); + case 55: + MigrationTo56.cleanUpFtsTable(db); } } }