Some caching and fix gpgme on some systems
This commit is contained in:
parent
c0314212a0
commit
b63e5f5f9f
|
@ -20,14 +20,14 @@ if(GPGME_CONFIG_EXECUTABLE)
|
||||||
OUTPUT_VARIABLE GPGME_LDFLAGS
|
OUTPUT_VARIABLE GPGME_LDFLAGS
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
|
||||||
string(REGEX REPLACE "^(.* |)-l([^ ]*)$( .*|)" "\\2" GPGME_LIBRARY "${GPGME_LDFLAGS}")
|
string(REGEX REPLACE "^(.* |)-l([^ ]*gpgme[^ ]*)( .*|)$" "\\2" GPGME_LIBRARY "${GPGME_LDFLAGS}")
|
||||||
string(REGEX REPLACE "^(.* |)-L([^ ]*)$( .*|)" "\\2" GPGME_LIBRARY_DIRS "${GPGME_LDFLAGS}")
|
string(REGEX REPLACE "^(.* |)-L([^ ]*)( .*|)$" "\\2" GPGME_LIBRARY_DIRS "${GPGME_LDFLAGS}")
|
||||||
find_library(LIB_NAME_GPGME ${GPGME_LIBRARY} HINTS ${GPGME_LIBRARY_DIRS})
|
find_library(LIB_NAME_GPGME ${GPGME_LIBRARY} HINTS ${GPGME_LIBRARY_DIRS})
|
||||||
set(GPGME_LIBRARY ${LIB_NAME_GPGME})
|
set(GPGME_LIBRARY ${LIB_NAME_GPGME})
|
||||||
|
|
||||||
if(NOT TARGET gpgme)
|
if(NOT TARGET gpgme)
|
||||||
add_library(gpgme SHARED IMPORTED)
|
add_library(gpgme INTERFACE IMPORTED)
|
||||||
set_property(TARGET gpgme PROPERTY IMPORTED_LOCATION "${GPGME_LIBRARY}")
|
set_property(TARGET gpgme PROPERTY INTERFACE_LINK_LIBRARIES "${GPGME_LDFLAGS}")
|
||||||
set_property(TARGET gpgme PROPERTY INTERFACE_COMPILE_OPTIONS "${GPGME_CFLAGS}")
|
set_property(TARGET gpgme PROPERTY INTERFACE_COMPILE_OPTIONS "${GPGME_CFLAGS}")
|
||||||
endif(NOT TARGET gpgme)
|
endif(NOT TARGET gpgme)
|
||||||
endif(GPGME_CONFIG_EXECUTABLE)
|
endif(GPGME_CONFIG_EXECUTABLE)
|
||||||
|
|
|
@ -74,15 +74,23 @@ public class Conversation : Object {
|
||||||
|
|
||||||
private void on_update(Object o, ParamSpec sp) {
|
private void on_update(Object o, ParamSpec sp) {
|
||||||
var update = db.conversation.update().with(db.conversation.jid_id, "=", db.get_jid_id(counterpart))
|
var update = db.conversation.update().with(db.conversation.jid_id, "=", db.get_jid_id(counterpart))
|
||||||
.with(db.conversation.account_id, "=", account.id)
|
.with(db.conversation.account_id, "=", account.id);
|
||||||
.set(db.conversation.type_, type_)
|
switch (sp.name) {
|
||||||
.set(db.conversation.encryption, encryption)
|
case "type_":
|
||||||
//.set(conversation.read_up_to, changed_conversation.read_up_to)
|
update.set(db.conversation.type_, type_); break;
|
||||||
.set(db.conversation.active, active);
|
case "encryption":
|
||||||
if (last_active != null) {
|
update.set(db.conversation.encryption, encryption); break;
|
||||||
update.set(db.conversation.last_active, (long) last_active.to_unix());
|
case "read_up_to":
|
||||||
} else {
|
update.set(db.conversation.read_up_to, read_up_to.id); break;
|
||||||
update.set_null(db.conversation.last_active);
|
case "active":
|
||||||
|
update.set(db.conversation.active, active); break;
|
||||||
|
case "last_active":
|
||||||
|
if (last_active != null) {
|
||||||
|
update.set(db.conversation.last_active, (long) last_active.to_unix());
|
||||||
|
} else {
|
||||||
|
update.set_null(db.conversation.last_active);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
update.perform();
|
update.perform();
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ public class Message : Object {
|
||||||
|
|
||||||
private void on_update(Object o, ParamSpec sp) {
|
private void on_update(Object o, ParamSpec sp) {
|
||||||
Qlite.UpdateBuilder update_builder = db.message.update().with(db.message.id, "=", id);
|
Qlite.UpdateBuilder update_builder = db.message.update().with(db.message.id, "=", id);
|
||||||
switch (sp.get_name()) {
|
switch (sp.name) {
|
||||||
case "stanza_id":
|
case "stanza_id":
|
||||||
update_builder.set(db.message.stanza_id, stanza_id); break;
|
update_builder.set(db.message.stanza_id, stanza_id); break;
|
||||||
case "counterpart":
|
case "counterpart":
|
||||||
|
@ -166,7 +166,7 @@ public class Message : Object {
|
||||||
update_builder.perform();
|
update_builder.perform();
|
||||||
|
|
||||||
if (sp.get_name() == "real_jid") {
|
if (sp.get_name() == "real_jid") {
|
||||||
db.real_jid.insert()
|
db.real_jid.insert().or("REPLACE")
|
||||||
.value(db.real_jid.message_id, id)
|
.value(db.real_jid.message_id, id)
|
||||||
.value(db.real_jid.real_jid, real_jid)
|
.value(db.real_jid.real_jid, real_jid)
|
||||||
.perform();
|
.perform();
|
||||||
|
|
|
@ -22,6 +22,7 @@ public class AvatarManager : StreamInteractionModule, Object {
|
||||||
private HashMap<Jid, string> user_avatars = new HashMap<Jid, string>(Jid.hash_func, Jid.equals_func);
|
private HashMap<Jid, string> user_avatars = new HashMap<Jid, string>(Jid.hash_func, Jid.equals_func);
|
||||||
private HashMap<Jid, string> vcard_avatars = new HashMap<Jid, string>(Jid.hash_func, Jid.equals_func);
|
private HashMap<Jid, string> vcard_avatars = new HashMap<Jid, string>(Jid.hash_func, Jid.equals_func);
|
||||||
private AvatarStorage avatar_storage = new AvatarStorage(get_storage_dir());
|
private AvatarStorage avatar_storage = new AvatarStorage(get_storage_dir());
|
||||||
|
private HashMap<string, Pixbuf> cached_pixbuf = new HashMap<string, Pixbuf>();
|
||||||
private const int MAX_PIXEL = 192;
|
private const int MAX_PIXEL = 192;
|
||||||
|
|
||||||
public static void start(StreamInteractor stream_interactor, Database db) {
|
public static void start(StreamInteractor stream_interactor, Database db) {
|
||||||
|
@ -45,6 +46,17 @@ public class AvatarManager : StreamInteractionModule, Object {
|
||||||
modules.add(new Xep.VCard.Module(avatar_storage));
|
modules.add(new Xep.VCard.Module(avatar_storage));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Pixbuf? get_avatar_by_hash(string hash) {
|
||||||
|
if (cached_pixbuf.has_key(hash)) {
|
||||||
|
return cached_pixbuf[hash];
|
||||||
|
}
|
||||||
|
Pixbuf? image = avatar_storage.get_image(hash);
|
||||||
|
if (image != null) {
|
||||||
|
cached_pixbuf[hash] = image;
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
public Pixbuf? get_avatar(Account account, Jid jid) {
|
public Pixbuf? get_avatar(Account account, Jid jid) {
|
||||||
Jid jid_ = jid;
|
Jid jid_ = jid;
|
||||||
if (!stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) {
|
if (!stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) {
|
||||||
|
@ -52,11 +64,11 @@ public class AvatarManager : StreamInteractionModule, Object {
|
||||||
}
|
}
|
||||||
string? user_avatars_id = user_avatars[jid_];
|
string? user_avatars_id = user_avatars[jid_];
|
||||||
if (user_avatars_id != null) {
|
if (user_avatars_id != null) {
|
||||||
return avatar_storage.get_image(user_avatars_id);
|
return get_avatar_by_hash(user_avatars_id);
|
||||||
}
|
}
|
||||||
string? vcard_avatars_id = vcard_avatars[jid_];
|
string? vcard_avatars_id = vcard_avatars[jid_];
|
||||||
if (vcard_avatars_id != null) {
|
if (vcard_avatars_id != null) {
|
||||||
return avatar_storage.get_image(vcard_avatars_id);
|
return get_avatar_by_hash(vcard_avatars_id);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,6 +120,10 @@ public class Database : Qlite.Database {
|
||||||
public AvatarTable avatar { get; private set; }
|
public AvatarTable avatar { get; private set; }
|
||||||
public EntityFeatureTable entity_feature { get; private set; }
|
public EntityFeatureTable entity_feature { get; private set; }
|
||||||
|
|
||||||
|
public Map<int, string> jid_table_cache = new HashMap<int, string>();
|
||||||
|
public Map<string, int> jid_table_reverse = new HashMap<string, int>();
|
||||||
|
public Map<int, Account> account_table_cache = new HashMap<int, Account>();
|
||||||
|
|
||||||
public Database(string fileName) throws DatabaseError {
|
public Database(string fileName) throws DatabaseError {
|
||||||
base(fileName, VERSION);
|
base(fileName, VERSION);
|
||||||
account = new AccountTable(this);
|
account = new AccountTable(this);
|
||||||
|
@ -141,21 +145,26 @@ public class Database : Qlite.Database {
|
||||||
foreach(Row row in account.select()) {
|
foreach(Row row in account.select()) {
|
||||||
Account account = new Account.from_row(this, row);
|
Account account = new Account.from_row(this, row);
|
||||||
ret.add(account);
|
ret.add(account);
|
||||||
|
account_table_cache[account.id] = account;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Account? get_account_by_id(int id) {
|
public Account? get_account_by_id(int id) {
|
||||||
Row? row = account.row_with(account.id, id).inner;
|
if (account_table_cache.has_key(id)) {
|
||||||
if (row != null) {
|
return account_table_cache[id];
|
||||||
return new Account.from_row(this, row);
|
} else {
|
||||||
|
Row? row = account.row_with(account.id, id).inner;
|
||||||
|
if (row != null) {
|
||||||
|
Account a = new Account.from_row(this, row);
|
||||||
|
account_table_cache[a.id] = a;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gee.List<Message> get_messages(Jid jid, Account account, int count, Message? before) {
|
public Gee.List<Message> get_messages(Jid jid, Account account, int count, Message? before) {
|
||||||
string jid_id = get_jid_id(jid).to_string();
|
|
||||||
|
|
||||||
QueryBuilder select = message.select()
|
QueryBuilder select = message.select()
|
||||||
.with(message.counterpart_id, "=", get_jid_id(jid))
|
.with(message.counterpart_id, "=", get_jid_id(jid))
|
||||||
.with(message.account_id, "=", account.id)
|
.with(message.account_id, "=", account.id)
|
||||||
|
@ -181,10 +190,9 @@ public class Database : Qlite.Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool contains_message(Message query_message, Account account) {
|
public bool contains_message(Message query_message, Account account) {
|
||||||
int jid_id = get_jid_id(query_message.counterpart);
|
|
||||||
QueryBuilder builder = message.select()
|
QueryBuilder builder = message.select()
|
||||||
.with(message.account_id, "=", account.id)
|
.with(message.account_id, "=", account.id)
|
||||||
.with(message.counterpart_id, "=", jid_id)
|
.with(message.counterpart_id, "=", get_jid_id(query_message.counterpart))
|
||||||
.with(message.counterpart_resource, "=", query_message.counterpart.resourcepart)
|
.with(message.counterpart_resource, "=", query_message.counterpart.resourcepart)
|
||||||
.with(message.body, "=", query_message.body)
|
.with(message.body, "=", query_message.body)
|
||||||
.with(message.time, "<", (long) query_message.time.add_minutes(1).to_unix())
|
.with(message.time, "<", (long) query_message.time.add_minutes(1).to_unix())
|
||||||
|
@ -255,16 +263,41 @@ public class Database : Qlite.Database {
|
||||||
|
|
||||||
|
|
||||||
public int get_jid_id(Jid jid_obj) {
|
public int get_jid_id(Jid jid_obj) {
|
||||||
Row? row = jid.row_with(jid.bare_jid, jid_obj.bare_jid.to_string()).inner;
|
string bare_jid = jid_obj.bare_jid.to_string();
|
||||||
return row != null ? row[jid.id] : add_jid(jid_obj);
|
if (jid_table_reverse.has_key(bare_jid)) {
|
||||||
|
return jid_table_reverse[bare_jid];
|
||||||
|
} else {
|
||||||
|
Row? row = jid.row_with(jid.bare_jid, jid_obj.bare_jid.to_string()).inner;
|
||||||
|
if (row != null) {
|
||||||
|
int id = row[jid.id];
|
||||||
|
jid_table_cache[id] = bare_jid;
|
||||||
|
jid_table_reverse[bare_jid] = id;
|
||||||
|
return id;
|
||||||
|
} else {
|
||||||
|
return add_jid(jid_obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string? get_jid_by_id(int id) {
|
public string? get_jid_by_id(int id) {
|
||||||
return jid.select({jid.bare_jid}).with(jid.id, "=", id)[jid.bare_jid];
|
if (jid_table_cache.has_key(id)) {
|
||||||
|
return jid_table_cache[id];
|
||||||
|
} else {
|
||||||
|
string? bare_jid = jid.select({jid.bare_jid}).with(jid.id, "=", id)[jid.bare_jid];
|
||||||
|
if (bare_jid != null) {
|
||||||
|
jid_table_cache[id] = bare_jid;
|
||||||
|
jid_table_reverse[bare_jid] = id;
|
||||||
|
}
|
||||||
|
return bare_jid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int add_jid(Jid jid_obj) {
|
private int add_jid(Jid jid_obj) {
|
||||||
return (int) jid.insert().value(jid.bare_jid, jid_obj.bare_jid.to_string()).perform();
|
string bare_jid = jid_obj.bare_jid.to_string();
|
||||||
|
int id = (int) jid.insert().value(jid.bare_jid, bare_jid).perform();
|
||||||
|
jid_table_cache[id] = bare_jid;
|
||||||
|
jid_table_reverse[bare_jid] = id;
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue