From 4b1bc435e564b7750ca5b5315107f943674cc1f1 Mon Sep 17 00:00:00 2001 From: Krille Date: Fri, 31 Mar 2023 13:09:01 +0200 Subject: [PATCH] fix: Clear HiveCollection boxes inside of transaction in order This makes sure that the deleteFromDisk() method is called AFTER the clear while the execution order was random before which could lead to the problem that Hive tries to clear a box after it got deleted. --- .../database/hive_collections_database.dart | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/src/database/hive_collections_database.dart b/lib/src/database/hive_collections_database.dart index 6bfb8b04..d5df5b68 100644 --- a/lib/src/database/hive_collections_database.dart +++ b/lib/src/database/hive_collections_database.dart @@ -242,28 +242,28 @@ class HiveCollectionsDatabase extends DatabaseApi { } @override - Future clear() => Future.wait([ - _clientBox.clear(), - _accountDataBox.clear(), - _roomsBox.clear(), - _roomStateBox.clear(), - _roomMembersBox.clear(), - _toDeviceQueueBox.clear(), - _roomAccountDataBox.clear(), - _inboundGroupSessionsBox.clear(), - _outboundGroupSessionsBox.clear(), - _olmSessionsBox.clear(), - _userDeviceKeysBox.clear(), - _userDeviceKeysOutdatedBox.clear(), - _userCrossSigningKeysBox.clear(), - _ssssCacheBox.clear(), - _presencesBox.clear(), - _timelineFragmentsBox.clear(), - _eventsBox.clear(), - _seenDeviceIdsBox.clear(), - _seenDeviceKeysBox.clear(), - _collection.deleteFromDisk(), - ]); + Future clear() => transaction(() async { + await _clientBox.clear(); + await _accountDataBox.clear(); + await _roomsBox.clear(); + await _roomStateBox.clear(); + await _roomMembersBox.clear(); + await _toDeviceQueueBox.clear(); + await _roomAccountDataBox.clear(); + await _inboundGroupSessionsBox.clear(); + await _outboundGroupSessionsBox.clear(); + await _olmSessionsBox.clear(); + await _userDeviceKeysBox.clear(); + await _userDeviceKeysOutdatedBox.clear(); + await _userCrossSigningKeysBox.clear(); + await _ssssCacheBox.clear(); + await _presencesBox.clear(); + await _timelineFragmentsBox.clear(); + await _eventsBox.clear(); + await _seenDeviceIdsBox.clear(); + await _seenDeviceKeysBox.clear(); + await _collection.deleteFromDisk(); + }); @override Future clearCache() => transaction(() async {