Skip to content

Commit

Permalink
fix: clear cache when clearing DB in MatrixSdkDatabase
Browse files Browse the repository at this point in the history
  • Loading branch information
coder-with-a-bushido committed Nov 26, 2024
1 parent fd2f909 commit 673dc1e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
12 changes: 7 additions & 5 deletions lib/src/database/indexeddb_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,22 @@ class Box<V> {
return;
}

void clearCache() {
_cache.clear();
_cachedKeys = null;
}

Future<void> clear([Transaction? txn]) async {
if (boxCollection._txnCache != null) {
boxCollection._txnCache!.add((txn) => clear(txn));
_cache.clear();
_cachedKeys = null;
clearCache();
return;
}

txn ??= boxCollection._db.transaction(name, 'readwrite');
final store = txn.objectStore(name);
await store.clear();
_cache.clear();
_cachedKeys = null;
return;
clearCache();
}

V? _fromValue(Object? value) {
Expand Down
27 changes: 26 additions & 1 deletion lib/src/database/matrix_sdk_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,32 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {
}

@override
Future<void> clear() => _collection.clear();
Future<void> clear() async {
_clientBox.clearCache();
_accountDataBox.clearCache();
_roomsBox.clearCache();
_preloadRoomStateBox.clearCache();
_nonPreloadRoomStateBox.clearCache();
_roomMembersBox.clearCache();
_toDeviceQueueBox.clearCache();
_roomAccountDataBox.clearCache();
_inboundGroupSessionsBox.clearCache();
_inboundGroupSessionsUploadQueueBox.clearCache();
_outboundGroupSessionsBox.clearCache();
_olmSessionsBox.clearCache();
_userDeviceKeysBox.clearCache();
_userDeviceKeysOutdatedBox.clearCache();
_userCrossSigningKeysBox.clearCache();
_ssssCacheBox.clearCache();
_presencesBox.clearCache();
_timelineFragmentsBox.clearCache();
_eventsBox.clearCache();
_seenDeviceIdsBox.clearCache();
_seenDeviceKeysBox.clearCache();
_userProfilesBox.clearCache();

await _collection.clear();
}

@override
Future<void> clearCache() => transaction(() async {
Expand Down
9 changes: 6 additions & 3 deletions lib/src/database/sqflite_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ class Box<V> {
return;
}

void clearCache() {
_cache.clear();
_cachedKeys = null;
}

Future<void> clear([Batch? txn]) async {
txn ??= boxCollection._activeBatch;

Expand All @@ -305,8 +310,6 @@ class Box<V> {
txn.delete(name);
}

_cache.clear();
_cachedKeys = null;
return;
clearCache();
}
}

0 comments on commit 673dc1e

Please sign in to comment.