TF-3767 Upgrade Hive database to version 16

Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
dab246
2025-06-11 12:17:45 +07:00
committed by Dat H. Pham
parent bce9620ac5
commit a02435c9f5
5 changed files with 30 additions and 1 deletions
@@ -0,0 +1,17 @@
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_database_steps.dart';
import 'package:tmail_ui_user/features/caching/caching_manager.dart';
class UpgradeHiveDatabaseStepsV16 extends UpgradeDatabaseSteps {
final CachingManager _cachingManager;
UpgradeHiveDatabaseStepsV16(this._cachingManager);
@override
Future<void> onUpgrade(int oldVersion, int newVersion) async {
if (oldVersion > 0 && oldVersion < newVersion && newVersion == 16) {
await _cachingManager.clearRecentSearchData();
}
}
}
@@ -15,6 +15,7 @@ import 'package:tmail_ui_user/features/caching/clients/new_email_hive_cache_clie
import 'package:tmail_ui_user/features/caching/clients/opened_email_hive_cache_client.dart'; import 'package:tmail_ui_user/features/caching/clients/opened_email_hive_cache_client.dart';
import 'package:tmail_ui_user/features/caching/clients/recent_login_url_cache_client.dart'; import 'package:tmail_ui_user/features/caching/clients/recent_login_url_cache_client.dart';
import 'package:tmail_ui_user/features/caching/clients/recent_login_username_cache_client.dart'; import 'package:tmail_ui_user/features/caching/clients/recent_login_username_cache_client.dart';
import 'package:tmail_ui_user/features/caching/clients/recent_search_cache_client.dart';
import 'package:tmail_ui_user/features/caching/clients/session_hive_cache_client.dart'; import 'package:tmail_ui_user/features/caching/clients/session_hive_cache_client.dart';
import 'package:tmail_ui_user/features/caching/clients/state_cache_client.dart'; import 'package:tmail_ui_user/features/caching/clients/state_cache_client.dart';
import 'package:tmail_ui_user/features/caching/config/hive_cache_config.dart'; import 'package:tmail_ui_user/features/caching/config/hive_cache_config.dart';
@@ -30,6 +31,7 @@ class CachingManager {
final MailboxCacheClient _mailboxCacheClient; final MailboxCacheClient _mailboxCacheClient;
final StateCacheClient _stateCacheClient; final StateCacheClient _stateCacheClient;
final EmailCacheClient _emailCacheClient; final EmailCacheClient _emailCacheClient;
final RecentSearchCacheClient _recentSearchCacheClient;
final RecentLoginUrlCacheClient _recentLoginUrlCacheClient; final RecentLoginUrlCacheClient _recentLoginUrlCacheClient;
final RecentLoginUsernameCacheClient _recentLoginUsernameCacheClient; final RecentLoginUsernameCacheClient _recentLoginUsernameCacheClient;
final AccountCacheClient _accountCacheClient; final AccountCacheClient _accountCacheClient;
@@ -48,6 +50,7 @@ class CachingManager {
this._mailboxCacheClient, this._mailboxCacheClient,
this._stateCacheClient, this._stateCacheClient,
this._emailCacheClient, this._emailCacheClient,
this._recentSearchCacheClient,
this._recentLoginUrlCacheClient, this._recentLoginUrlCacheClient,
this._recentLoginUsernameCacheClient, this._recentLoginUsernameCacheClient,
this._accountCacheClient, this._accountCacheClient,
@@ -195,4 +198,8 @@ class CachingManager {
_recentLoginUsernameCacheClient.clearAllData(), _recentLoginUsernameCacheClient.clearAllData(),
]); ]);
} }
Future<void> clearRecentSearchData() async {
await _recentSearchCacheClient.clearAllData();
}
} }
@@ -1,4 +1,4 @@
class CacheVersion { class CacheVersion {
static const int hiveDBVersion = 15; static const int hiveDBVersion = 16;
} }
@@ -11,6 +11,8 @@ import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_st
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v12.dart'; import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v12.dart';
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v13.dart'; import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v13.dart';
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v14.dart'; import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v14.dart';
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v15.dart';
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v16.dart';
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v7.dart'; import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v7.dart';
import 'package:tmail_ui_user/features/caching/caching_manager.dart'; import 'package:tmail_ui_user/features/caching/caching_manager.dart';
import 'package:tmail_ui_user/features/caching/config/cache_version.dart'; import 'package:tmail_ui_user/features/caching/config/cache_version.dart';
@@ -74,6 +76,8 @@ class HiveCacheConfig {
await UpgradeHiveDatabaseStepsV12(cachingManager).onUpgrade(oldVersion, newVersion); await UpgradeHiveDatabaseStepsV12(cachingManager).onUpgrade(oldVersion, newVersion);
await UpgradeHiveDatabaseStepsV13(cachingManager).onUpgrade(oldVersion, newVersion); await UpgradeHiveDatabaseStepsV13(cachingManager).onUpgrade(oldVersion, newVersion);
await UpgradeHiveDatabaseStepsV14(cachingManager).onUpgrade(oldVersion, newVersion); await UpgradeHiveDatabaseStepsV14(cachingManager).onUpgrade(oldVersion, newVersion);
await UpgradeHiveDatabaseStepsV15(cachingManager).onUpgrade(oldVersion, newVersion);
await UpgradeHiveDatabaseStepsV16(cachingManager).onUpgrade(oldVersion, newVersion);
if (oldVersion != newVersion) { if (oldVersion != newVersion) {
await cachingManager.storeCacheVersion(newVersion); await cachingManager.storeCacheVersion(newVersion);
@@ -94,6 +94,7 @@ class LocalBindings extends Bindings {
Get.find<MailboxCacheClient>(), Get.find<MailboxCacheClient>(),
Get.find<StateCacheClient>(), Get.find<StateCacheClient>(),
Get.find<EmailCacheClient>(), Get.find<EmailCacheClient>(),
Get.find<RecentSearchCacheClient>(),
Get.find<RecentLoginUrlCacheClient>(), Get.find<RecentLoginUrlCacheClient>(),
Get.find<RecentLoginUsernameCacheClient>(), Get.find<RecentLoginUsernameCacheClient>(),
Get.find<AccountCacheClient>(), Get.find<AccountCacheClient>(),