Improve database performance while reconnecting and syncing

Also move some tasks to low priority idle queue so they won't block UI updates
This commit is contained in:
Marvin W 2023-03-20 15:40:44 -06:00
parent 89b9110fcb
commit 481a68fd89
No known key found for this signature in database
GPG key ID: 072E9235DB996F2A
2 changed files with 20 additions and 1 deletions

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 = 25; private const int VERSION = 26;
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 };
@ -93,6 +93,11 @@ public class Database : Qlite.Database {
// deduplication // deduplication
index("message_account_counterpart_stanzaid_idx", {account_id, counterpart_id, stanza_id}); index("message_account_counterpart_stanzaid_idx", {account_id, counterpart_id, stanza_id});
index("message_account_counterpart_serverid_idx", {account_id, counterpart_id, server_id});
// message by marked
index("message_account_marked_idx", {account_id, marked});
fts({body}); fts({body});
} }
} }

View file

@ -225,7 +225,21 @@ public class ConversationSelectorRow : ListBoxRow {
label.attributes = copy; label.attributes = copy;
} }
private bool update_read_pending = false;
private bool update_read_pending_force = false;
protected void update_read(bool force_update = false) { protected void update_read(bool force_update = false) {
if (force_update) update_read_pending_force = true;
if (update_read_pending) return;
update_read_pending = true;
Idle.add(() => {
update_read_pending = false;
update_read_pending_force = false;
update_read_idle(update_read_pending_force);
return Source.REMOVE;
}, Priority.LOW);
}
private void update_read_idle(bool force_update = false) {
int current_num_unread = stream_interactor.get_module(ChatInteraction.IDENTITY).get_num_unread(conversation); int current_num_unread = stream_interactor.get_module(ChatInteraction.IDENTITY).get_num_unread(conversation);
if (num_unread == current_num_unread && !force_update) return; if (num_unread == current_num_unread && !force_update) return;
num_unread = current_num_unread; num_unread = current_num_unread;