From 673dc1e5277f48f80415722b561692c8eafd701d Mon Sep 17 00:00:00 2001 From: Karthikeyan S Date: Tue, 26 Nov 2024 16:28:48 +0530 Subject: [PATCH] fix: clear cache when clearing DB in MatrixSdkDatabase --- lib/src/database/indexeddb_box.dart | 12 +++++----- lib/src/database/matrix_sdk_database.dart | 27 ++++++++++++++++++++++- lib/src/database/sqflite_box.dart | 9 +++++--- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/lib/src/database/indexeddb_box.dart b/lib/src/database/indexeddb_box.dart index 268006a1..56a2c363 100644 --- a/lib/src/database/indexeddb_box.dart +++ b/lib/src/database/indexeddb_box.dart @@ -213,20 +213,22 @@ class Box { return; } + void clearCache() { + _cache.clear(); + _cachedKeys = null; + } + Future 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) { diff --git a/lib/src/database/matrix_sdk_database.dart b/lib/src/database/matrix_sdk_database.dart index 9b37237c..62201808 100644 --- a/lib/src/database/matrix_sdk_database.dart +++ b/lib/src/database/matrix_sdk_database.dart @@ -338,7 +338,32 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage { } @override - Future clear() => _collection.clear(); + Future 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 clearCache() => transaction(() async { diff --git a/lib/src/database/sqflite_box.dart b/lib/src/database/sqflite_box.dart index 4ab23115..fae78b95 100644 --- a/lib/src/database/sqflite_box.dart +++ b/lib/src/database/sqflite_box.dart @@ -296,6 +296,11 @@ class Box { return; } + void clearCache() { + _cache.clear(); + _cachedKeys = null; + } + Future clear([Batch? txn]) async { txn ??= boxCollection._activeBatch; @@ -305,8 +310,6 @@ class Box { txn.delete(name); } - _cache.clear(); - _cachedKeys = null; - return; + clearCache(); } }