From 2eb72d5dad9be99dc110417144db2f8c4446bd53 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Tue, 10 Mar 2020 23:53:11 +0100 Subject: Fix+optimize contact-to-avatar storage and loading --- libdino/src/service/database.vala | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) (limited to 'libdino/src/service/database.vala') diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala index 238d8f46..34bbea7a 100644 --- a/libdino/src/service/database.vala +++ b/libdino/src/service/database.vala @@ -7,7 +7,7 @@ using Dino.Entities; namespace Dino { public class Database : Qlite.Database { - private const int VERSION = 11; + private const int VERSION = 12; public class AccountTable : Table { public Column id = new Column.Integer("id") { primary_key = true, auto_increment = true }; @@ -150,13 +150,15 @@ public class Database : Qlite.Database { } public class AvatarTable : Table { - public Column jid = new Column.Text("jid"); + public Column jid_id = new Column.Integer("jid_id"); + public Column account_id = new Column.Integer("account_id"); public Column hash = new Column.Text("hash"); public Column type_ = new Column.Integer("type"); internal AvatarTable(Database db) { - base(db, "avatar"); - init({jid, hash, type_}); + base(db, "contact_avatar"); + init({jid_id, account_id, hash, type_}); + unique({jid_id, account_id}, "REPLACE"); } } @@ -309,6 +311,13 @@ public class Database : Qlite.Database { error("Failed to upgrade to database version 11: %s", e.message); } } + if (oldVersion < 12) { + try { + exec("delete from avatar"); + } catch (Error e) { + error("Failed to upgrade to database version 12: %s", e.message); + } + } } public ArrayList get_accounts() { @@ -424,26 +433,6 @@ public class Database : Qlite.Database { return ret; } - public void set_avatar_hash(Jid jid, string hash, int type) { - avatar.insert().or("REPLACE") - .value(avatar.jid, jid.to_string()) - .value(avatar.hash, hash) - .value(avatar.type_, type) - .perform(); - } - - public HashMap get_avatar_hashes(int type) { - HashMap ret = new HashMap(Jid.hash_func, Jid.equals_func); - foreach (Row row in avatar.select({avatar.jid, avatar.hash}).with(avatar.type_, "=", type)) { - try { - ret[new Jid(row[avatar.jid])] = row[avatar.hash]; - } catch (InvalidJidError e) { - warning("Ignoring avatar of invalid Jid: %s", e.message); - } - } - return ret; - } - public void add_entity_features(string entity, Gee.List features) { foreach (string feature in features) { entity_feature.insert() -- cgit v1.2.3-70-g09d2