mirror of https://github.com/M66B/FairEmail.git
Lookup by hash (experimental)
This commit is contained in:
parent
3cafd18c6e
commit
105dc80e34
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
|
|
|
@ -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`)");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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)")
|
||||
|
|
|
@ -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"}),
|
||||
|
|
Loading…
Reference in New Issue