[Store] Async storing of prev batch

This commit is contained in:
Christian Pauly 2020-01-06 20:21:25 +00:00
parent 3fbb837f85
commit 4d1e5e3ed3
2 changed files with 9 additions and 6 deletions

View File

@ -721,13 +721,16 @@ class Client {
if (this.store != null) {
await this.store.transaction(() {
handleSync(syncResp);
this.store.storePrevBatch(syncResp);
return;
this.store.storePrevBatch(syncResp["next_batch"]);
});
} else {
await handleSync(syncResp);
}
if (this.prevBatch == null) this.onFirstSync.add(true);
if (this.prevBatch == null) {
this.onFirstSync.add(true);
this.prevBatch = syncResp["next_batch"];
_sortRooms();
}
this.prevBatch = syncResp["next_batch"];
if (hash == _syncRequest.hashCode) unawaited(_sync());
} on MatrixException catch (exception) {
@ -1042,7 +1045,7 @@ class Client {
.compareTo(a.timeCreated.millisecondsSinceEpoch);
_sortRooms() {
if (_sortLock || rooms.length < 2) return;
if (prevBatch == null || _sortLock || rooms.length < 2) return;
_sortLock = true;
rooms?.sort(sortRoomsBy);
_sortLock = false;

View File

@ -48,11 +48,11 @@ abstract class StoreAPI {
var txn;
Future<void> transaction(Future<void> queries());
Future<void> transaction(void queries());
/// Will be automatically called on every synchronisation. Must be called inside of
// /// [transaction].
Future<void> storePrevBatch(dynamic sync);
void storePrevBatch(String prevBatch);
Future<void> storeRoomPrevBatch(Room room);