only lazy-load m.room.member, not store presence

This commit is contained in:
Sorunome 2020-06-30 13:41:52 +02:00
parent 2e3d8205b1
commit b7b369923f
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
5 changed files with 10 additions and 63 deletions

View File

@ -651,7 +651,7 @@ class Client {
}
_sortRooms();
accountData = await database.getAccountData(id);
presences = await database.getPresences(id);
presences.clear();
}
onLoginStateChanged.add(LoginState.logged);
@ -744,14 +744,6 @@ class Client {
}
if (sync.presence != null) {
for (final newPresence in sync.presence) {
if (database != null) {
await database.storePresence(
id,
newPresence.type,
newPresence.senderId,
jsonEncode(newPresence.toJson()),
);
}
presences[newPresence.senderId] = newPresence;
onPresence.add(newPresence);
}

View File

@ -192,22 +192,6 @@ class Database extends _$Database {
return newAccountData;
}
Future<Map<String, api.Presence>> getPresences(int clientId) async {
final newPresences = <String, api.Presence>{};
final rawPresences = await getAllPresences(clientId).get();
for (final d in rawPresences) {
// TODO: Why is this not working?
try {
final content = sdk.Event.getMapFromPayload(d.content);
var presence = api.Presence.fromJson(content);
presence.senderId = d.sender;
presence.type = d.type;
newPresences[d.sender] = api.Presence.fromJson(content);
} catch (_) {}
}
return newPresences;
}
/// Stores a RoomUpdate object in the database. Must be called inside of
/// [transaction].
final Set<String> _ensuredRooms = {};

View File

@ -5999,35 +5999,6 @@ abstract class _$Database extends GeneratedDatabase {
);
}
DbPresence _rowToDbPresence(QueryRow row) {
return DbPresence(
clientId: row.readInt('client_id'),
type: row.readString('type'),
sender: row.readString('sender'),
content: row.readString('content'),
);
}
Selectable<DbPresence> getAllPresences(int client_id) {
return customSelect('SELECT * FROM presences WHERE client_id = :client_id',
variables: [Variable.withInt(client_id)],
readsFrom: {presences}).map(_rowToDbPresence);
}
Future<int> storePresence(
int client_id, String type, String sender, String content) {
return customInsert(
'INSERT OR REPLACE INTO presences (client_id, type, sender, content) VALUES (:client_id, :type, :sender, :content)',
variables: [
Variable.withInt(client_id),
Variable.withString(type),
Variable.withString(sender),
Variable.withString(content)
],
updates: {presences},
);
}
Future<int> updateEvent(String unsigned, String content, String prev_content,
int client_id, String event_id, String room_id) {
return customUpdate(
@ -6079,7 +6050,7 @@ abstract class _$Database extends GeneratedDatabase {
Selectable<DbRoomState> getImportantRoomStates(int client_id) {
return customSelect(
'SELECT * FROM room_states WHERE client_id = :client_id AND type IN (\'m.room.name\', \'m.room.avatar\', \'m.room.message\', \'m.room.encrypted\', \'m.room.encryption\')',
'SELECT * FROM room_states WHERE client_id = :client_id AND type <> \'m.room.member\'',
variables: [Variable.withInt(client_id)],
readsFrom: {roomStates}).map(_rowToDbRoomState);
}
@ -6091,10 +6062,10 @@ abstract class _$Database extends GeneratedDatabase {
readsFrom: {roomStates}).map(_rowToDbRoomState);
}
Selectable<DbRoomState> getAllRoomStatesForRoom(
Selectable<DbRoomState> getUnimportantRoomStatesForRoom(
int client_id, String room_id) {
return customSelect(
'SELECT * FROM room_states WHERE client_id = :client_id AND room_id = :room_id',
'SELECT * FROM room_states WHERE client_id = :client_id AND room_id = :room_id AND type = \'m.room.member\'',
variables: [Variable.withInt(client_id), Variable.withString(room_id)],
readsFrom: {roomStates}).map(_rowToDbRoomState);
}

View File

@ -206,13 +206,12 @@ setRoomPrevBatch: UPDATE rooms SET prev_batch = :prev_batch WHERE client_id = :c
updateRoomSortOrder: UPDATE rooms SET oldest_sort_order = :oldest_sort_order, newest_sort_order = :newest_sort_order WHERE client_id = :client_id AND room_id = :room_id;
getAllAccountData: SELECT * FROM account_data WHERE client_id = :client_id;
storeAccountData: INSERT OR REPLACE INTO account_data (client_id, type, content) VALUES (:client_id, :type, :content);
getAllPresences: SELECT * FROM presences WHERE client_id = :client_id;
storePresence: INSERT OR REPLACE INTO presences (client_id, type, sender, content) VALUES (:client_id, :type, :sender, :content);
updateEvent: UPDATE events SET unsigned = :unsigned, content = :content, prev_content = :prev_content WHERE client_id = :client_id AND event_id = :event_id AND room_id = :room_id;
updateEventStatus: UPDATE events SET status = :status, event_id = :new_event_id WHERE client_id = :client_id AND event_id = :old_event_id AND room_id = :room_id;
getImportantRoomStates: SELECT * FROM room_states WHERE client_id = :client_id AND type IN ('m.room.name', 'm.room.avatar', 'm.room.message', 'm.room.encrypted', 'm.room.encryption');
--getImportantRoomStates: SELECT * FROM room_states WHERE client_id = :client_id AND type IN ('m.room.name', 'm.room.avatar', 'm.room.message', 'm.room.encrypted', 'm.room.encryption', 'im.ponies.room_emotes');
getImportantRoomStates: SELECT * FROM room_states WHERE client_id = :client_id AND type <> 'm.room.member';
getAllRoomStates: SELECT * FROM room_states WHERE client_id = :client_id;
getAllRoomStatesForRoom: SELECT * FROM room_states WHERE client_id = :client_id AND room_id = :room_id;
getUnimportantRoomStatesForRoom: SELECT * FROM room_states WHERE client_id = :client_id AND room_id = :room_id AND type = 'm.room.member';
storeEvent: INSERT OR REPLACE INTO events (client_id, event_id, room_id, sort_order, origin_server_ts, sender, type, unsigned, content, prev_content, state_key, status) VALUES (:client_id, :event_id, :room_id, :sort_order, :origin_server_ts, :sender, :type, :unsigned, :content, :prev_content, :state_key, :status);
storeRoomState: INSERT OR REPLACE INTO room_states (client_id, event_id, room_id, sort_order, origin_server_ts, sender, type, unsigned, content, prev_content, state_key) VALUES (:client_id, :event_id, :room_id, :sort_order, :origin_server_ts, :sender, :type, :unsigned, :content, :prev_content, :state_key);
getAllRoomAccountData: SELECT * FROM room_account_data WHERE client_id = :client_id;

View File

@ -106,8 +106,9 @@ class Room {
if (!partial || client.database == null) {
return;
}
final allStates =
await client.database.getAllRoomStatesForRoom(client.id, id).get();
final allStates = await client.database
.getUnimportantRoomStatesForRoom(client.id, id)
.get();
for (final state in allStates) {
final newState = Event.fromDb(state, this);
setState(newState);