Lookup by hash (experimental)

This commit is contained in:
M66B 2020-04-01 14:39:09 +02:00
parent 3cafd18c6e
commit 105dc80e34
5 changed files with 2245 additions and 1 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2068,6 +2068,17 @@ class Core {
// Find message by uid (fast, no headers required)
EntityMessage message = db.message().getMessageByUid(folder.id, uid);
// Find message by internal hash (slow, headers required)
// - pre moved messages
if (message == null) {
String hash = helper.getHash();
List<EntityMessage> existing = db.message().getMessagesByHash(folder.id, hash);
if (existing != null && existing.size() == 1) {
Log.i(folder.name + " found by hash=" + hash);
message = existing.get(0);
}
}
// Find message by Message-ID (slow, headers required)
// - messages in inbox have same id as message sent to self
// - messages in archive have same id as original

View File

@ -60,7 +60,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 152,
version = 153,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -1444,6 +1444,13 @@ public abstract class DB extends RoomDatabase {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `hash` TEXT");
}
})
.addMigrations(new Migration(152, 153) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("CREATE INDEX IF NOT EXISTS `index_message_folder_hash` ON `message` (`folder`, `hash`)");
}
});
}

View File

@ -324,6 +324,11 @@ public interface DaoMessage {
" AND msgid = :msgid")
List<EntityMessage> getMessagesByMsgId(long account, String msgid);
@Query("SELECT * FROM message" +
" WHERE folder = :folder" +
" AND hash = :hash")
List<EntityMessage> getMessagesByHash(long folder, String hash);
@Query("SELECT * FROM message" +
" WHERE account = :account" +
" AND (id = :id OR msgid = :msgid)")

View File

@ -63,6 +63,7 @@ import static androidx.room.ForeignKey.SET_NULL;
@Index(value = {"folder"}),
@Index(value = {"identity"}),
@Index(value = {"folder", "uid"}, unique = true),
@Index(value = {"folder", "hash"}),
@Index(value = {"msgid"}),
@Index(value = {"thread"}),
@Index(value = {"sender"}),