refactor: Improve clearing

This makes sure that the database is null after clearing so it will
be built again using the databaseBuilder.
Also this makes sure that the sync has
aborted BEFORE the clearing starts to
get rid of some warnings in the logs.
This commit is contained in:
Christian Pauly 2021-06-14 08:30:27 +02:00
parent fe06b96e93
commit 28dc8b4ff0
1 changed files with 6 additions and 0 deletions

View File

@ -912,6 +912,7 @@ class Client extends MatrixApi {
}
await legacyDatabase.close();
if (migrateClient != null) {
_initLock = false;
return init();
}
}
@ -992,10 +993,15 @@ class Client extends MatrixApi {
Future<void> clear() async {
Logs().outputEvents.clear();
try {
await abortSync();
await database?.clear(id);
_backgroundSync = true;
} catch (e, s) {
Logs().e('Unable to clear database', e, s);
} finally {
_database = null;
}
_id = accessToken = syncFilterId =
homeserver = _userID = _deviceID = _deviceName = prevBatch = null;
_rooms = [];