TF-2310 Upgrade hive database to version 10
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
abstract class UpgradeDatabaseSteps {
|
||||||
|
Future<void> onUpgrade(int oldVersion, int newVersion);
|
||||||
|
}
|
||||||
@@ -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 UpgradeHiveDatabaseStepsV10 extends UpgradeDatabaseSteps {
|
||||||
|
|
||||||
|
final CachingManager _cachingManager;
|
||||||
|
|
||||||
|
UpgradeHiveDatabaseStepsV10(this._cachingManager);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onUpgrade(int oldVersion, int newVersion) async {
|
||||||
|
if (oldVersion > 0 && oldVersion < newVersion && newVersion == 10) {
|
||||||
|
await _cachingManager.clearLoginRecentData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 UpgradeHiveDatabaseStepsV7 extends UpgradeDatabaseSteps {
|
||||||
|
|
||||||
|
final CachingManager _cachingManager;
|
||||||
|
|
||||||
|
UpgradeHiveDatabaseStepsV7(this._cachingManager);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onUpgrade(int oldVersion, int newVersion) async {
|
||||||
|
if (oldVersion > 0 && oldVersion < newVersion && newVersion == 7) {
|
||||||
|
await _cachingManager.clearAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,8 @@ import 'package:tmail_ui_user/features/caching/clients/hive_cache_version_client
|
|||||||
import 'package:tmail_ui_user/features/caching/clients/mailbox_cache_client.dart';
|
import 'package:tmail_ui_user/features/caching/clients/mailbox_cache_client.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/clients/new_email_hive_cache_client.dart';
|
import 'package:tmail_ui_user/features/caching/clients/new_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/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_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/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';
|
||||||
@@ -26,6 +28,8 @@ class CachingManager {
|
|||||||
final StateCacheClient _stateCacheClient;
|
final StateCacheClient _stateCacheClient;
|
||||||
final EmailCacheClient _emailCacheClient;
|
final EmailCacheClient _emailCacheClient;
|
||||||
final RecentSearchCacheClient _recentSearchCacheClient;
|
final RecentSearchCacheClient _recentSearchCacheClient;
|
||||||
|
final RecentLoginUrlCacheClient _recentLoginUrlCacheClient;
|
||||||
|
final RecentLoginUsernameCacheClient _recentLoginUsernameCacheClient;
|
||||||
final AccountCacheClient _accountCacheClient;
|
final AccountCacheClient _accountCacheClient;
|
||||||
final FcmCacheClient _fcmCacheClient;
|
final FcmCacheClient _fcmCacheClient;
|
||||||
final FirebaseRegistrationCacheClient _firebaseRegistrationCacheClient;
|
final FirebaseRegistrationCacheClient _firebaseRegistrationCacheClient;
|
||||||
@@ -43,6 +47,8 @@ class CachingManager {
|
|||||||
this._stateCacheClient,
|
this._stateCacheClient,
|
||||||
this._emailCacheClient,
|
this._emailCacheClient,
|
||||||
this._recentSearchCacheClient,
|
this._recentSearchCacheClient,
|
||||||
|
this._recentLoginUrlCacheClient,
|
||||||
|
this._recentLoginUsernameCacheClient,
|
||||||
this._accountCacheClient,
|
this._accountCacheClient,
|
||||||
this._fcmCacheClient,
|
this._fcmCacheClient,
|
||||||
this._firebaseRegistrationCacheClient,
|
this._firebaseRegistrationCacheClient,
|
||||||
@@ -110,15 +116,6 @@ class CachingManager {
|
|||||||
], eagerError: true);
|
], eagerError: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> onUpgradeCache(int oldVersion, int newVersion) async {
|
|
||||||
log('CachingManager::onUpgradeCache():oldVersion $oldVersion | newVersion: $newVersion');
|
|
||||||
await clearData();
|
|
||||||
if (oldVersion > 0 && oldVersion < newVersion && newVersion == 7) {
|
|
||||||
await clearAll();
|
|
||||||
}
|
|
||||||
await storeCacheVersion(newVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<bool> storeCacheVersion(int newVersion) async {
|
Future<bool> storeCacheVersion(int newVersion) async {
|
||||||
log('CachingManager::storeCacheVersion()');
|
log('CachingManager::storeCacheVersion()');
|
||||||
return _hiveCacheVersionClient.storeVersion(newVersion);
|
return _hiveCacheVersionClient.storeVersion(newVersion);
|
||||||
@@ -138,4 +135,11 @@ class CachingManager {
|
|||||||
_fileUtils.removeFolder(CachingConstants.openedEmailContentFolderName),
|
_fileUtils.removeFolder(CachingConstants.openedEmailContentFolderName),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> clearLoginRecentData() async {
|
||||||
|
await Future.wait([
|
||||||
|
_recentLoginUrlCacheClient.clearAllData(),
|
||||||
|
_recentLoginUsernameCacheClient.clearAllData(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
class CacheVersion {
|
class CacheVersion {
|
||||||
static const int hiveDBVersion = 9;
|
static const int hiveDBVersion = 10;
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,8 @@ import 'package:core/utils/app_logger.dart';
|
|||||||
import 'package:core/utils/platform_info.dart';
|
import 'package:core/utils/platform_info.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:path_provider/path_provider.dart' as path_provider;
|
import 'package:path_provider/path_provider.dart' as path_provider;
|
||||||
|
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_hive_database_steps_v10.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';
|
||||||
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
|
||||||
@@ -60,9 +62,11 @@ class HiveCacheConfig {
|
|||||||
final oldVersion = await cachingManager.getLatestVersion() ?? 0;
|
final oldVersion = await cachingManager.getLatestVersion() ?? 0;
|
||||||
const newVersion = CacheVersion.hiveDBVersion;
|
const newVersion = CacheVersion.hiveDBVersion;
|
||||||
log('HiveCacheConfig::onUpgradeDatabase():oldVersion: $oldVersion | newVersion: $newVersion');
|
log('HiveCacheConfig::onUpgradeDatabase():oldVersion: $oldVersion | newVersion: $newVersion');
|
||||||
if (oldVersion != newVersion) {
|
|
||||||
await cachingManager.onUpgradeCache(oldVersion, newVersion);
|
await UpgradeHiveDatabaseStepsV7(cachingManager).onUpgrade(oldVersion, newVersion);
|
||||||
}
|
await UpgradeHiveDatabaseStepsV10(cachingManager).onUpgrade(oldVersion, newVersion);
|
||||||
|
|
||||||
|
await cachingManager.storeCacheVersion(newVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> initializeEncryptionKey() async {
|
Future<void> initializeEncryptionKey() async {
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ class LocalBindings extends Bindings {
|
|||||||
Get.find<StateCacheClient>(),
|
Get.find<StateCacheClient>(),
|
||||||
Get.find<EmailCacheClient>(),
|
Get.find<EmailCacheClient>(),
|
||||||
Get.find<RecentSearchCacheClient>(),
|
Get.find<RecentSearchCacheClient>(),
|
||||||
|
Get.find<RecentLoginUrlCacheClient>(),
|
||||||
|
Get.find<RecentLoginUsernameCacheClient>(),
|
||||||
Get.find<AccountCacheClient>(),
|
Get.find<AccountCacheClient>(),
|
||||||
Get.find<FcmCacheClient>(),
|
Get.find<FcmCacheClient>(),
|
||||||
Get.find<FirebaseRegistrationCacheClient>(),
|
Get.find<FirebaseRegistrationCacheClient>(),
|
||||||
|
|||||||
Reference in New Issue
Block a user