Improve content_item db table index

fixes #923

Co-authored-by: eta <eta@theta.eu.org>
This commit is contained in:
fiaxh 2020-11-05 17:09:15 +01:00
parent 6218b759bf
commit 1999c97bb9

View file

@ -7,7 +7,7 @@ using Dino.Entities;
namespace Dino { namespace Dino {
public class Database : Qlite.Database { public class Database : Qlite.Database {
private const int VERSION = 16; private const int VERSION = 17;
public class AccountTable : Table { public class AccountTable : Table {
public Column<int> id = new Column.Integer("id") { primary_key = true, auto_increment = true }; public Column<int> id = new Column.Integer("id") { primary_key = true, auto_increment = true };
@ -62,7 +62,7 @@ public class Database : Qlite.Database {
internal ContentItemTable(Database db) { internal ContentItemTable(Database db) {
base(db, "content_item"); base(db, "content_item");
init({id, conversation_id, time, local_time, content_type, foreign_id, hide}); init({id, conversation_id, time, local_time, content_type, foreign_id, hide});
index("contentitem_localtime_counterpart_idx", {local_time, conversation_id}); index("contentitem_conversation_hide_localtime_time_idx", {conversation_id, hide, local_time, time});
unique({content_type, foreign_id}, "IGNORE"); unique({content_type, foreign_id}, "IGNORE");
} }
} }
@ -390,6 +390,14 @@ public class Database : Qlite.Database {
error("Failed to upgrade to database version 16: %s", e.message); error("Failed to upgrade to database version 16: %s", e.message);
} }
} }
if (oldVersion < 17) {
try {
exec("DROP INDEX contentitem_localtime_counterpart_idx");
exec("CREATE INDEX contentitem_conversation_hide_localtime_time_idx ON content_item (conversation_id, hide, local_time, time)");
} catch (Error e) {
error("Failed to upgrade to database version 17: %s", e.message);
}
}
} }
public ArrayList<Account> get_accounts() { public ArrayList<Account> get_accounts() {