Migrate Hive box To IsolatedHive box
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/recent_login_url_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/interaction/cache_manager_interaction.dart';
|
||||
import 'package:tmail_ui_user/features/cleanup/domain/model/recent_login_url_cleanup_rule.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/model/recent_login_url_cache.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/extensions/list_recent_login_url_extension.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/model/recent_login_url.dart';
|
||||
|
||||
class RecentLoginUrlCacheManager {
|
||||
class RecentLoginUrlCacheManager extends CacheManagerInteraction {
|
||||
|
||||
final RecentLoginUrlCacheClient _recentLoginUrlCacheClient;
|
||||
|
||||
@@ -21,4 +25,69 @@ class RecentLoginUrlCacheManager {
|
||||
await _recentLoginUrlCacheClient.deleteMultipleItem(newListKeyRecent);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> saveLoginUrl(RecentLoginUrlCache recentLoginUrlCache) async {
|
||||
final isExist = await _recentLoginUrlCacheClient.isExistItem(
|
||||
recentLoginUrlCache.url,
|
||||
);
|
||||
|
||||
if (isExist) {
|
||||
await _recentLoginUrlCacheClient.updateItem(
|
||||
recentLoginUrlCache.url,
|
||||
recentLoginUrlCache,
|
||||
);
|
||||
} else {
|
||||
await _recentLoginUrlCacheClient.insertItem(
|
||||
recentLoginUrlCache.url,
|
||||
recentLoginUrlCache,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<RecentLoginUrl>> getAllRecentLoginUrlLatest({
|
||||
int? limit,
|
||||
String? pattern,
|
||||
}) async {
|
||||
final listRecentUrlCache = await _recentLoginUrlCacheClient.getAll();
|
||||
final listRecentUrl = listRecentUrlCache
|
||||
.where((recentCache) => _filterRecentUrlCache(recentCache, pattern))
|
||||
.map((recentCache) => recentCache.toRecentLoginUrl())
|
||||
.toList();
|
||||
listRecentUrl.sortByCreationDate();
|
||||
|
||||
final newLimit = limit ?? 5;
|
||||
|
||||
final newListRecentSUrl = listRecentUrl.length > newLimit
|
||||
? listRecentUrl.sublist(0, newLimit)
|
||||
: listRecentUrl;
|
||||
|
||||
return newListRecentSUrl;
|
||||
}
|
||||
|
||||
bool _filterRecentUrlCache(
|
||||
RecentLoginUrlCache recentLoginUrlCache,
|
||||
String? pattern,
|
||||
) {
|
||||
if (pattern == null || pattern.trim().isEmpty) {
|
||||
return true;
|
||||
} else {
|
||||
return recentLoginUrlCache.matchUrl(pattern);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> clear() => _recentLoginUrlCacheClient.clearAllData();
|
||||
|
||||
@override
|
||||
Future<void> migrateHiveToIsolatedHive() async {
|
||||
try {
|
||||
final legacyMapItems = await _recentLoginUrlCacheClient.getMapItems(
|
||||
isolated: false,
|
||||
);
|
||||
log('$runtimeType::migrateHiveToIsolatedHive(): Length of legacyMapItems: ${legacyMapItems.length}');
|
||||
await _recentLoginUrlCacheClient.insertMultipleItem(legacyMapItems);
|
||||
log('$runtimeType::migrateHiveToIsolatedHive(): ✅ Migrate Hive box "${_recentLoginUrlCacheClient.tableName}" → IsolatedHive DONE');
|
||||
} catch (e) {
|
||||
logError('$runtimeType::migrateHiveToIsolatedHive(): ❌ Migrate Hive box "${_recentLoginUrlCacheClient.tableName}" → IsolatedHive FAILED, Error: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/recent_login_username_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/interaction/cache_manager_interaction.dart';
|
||||
import 'package:tmail_ui_user/features/cleanup/domain/model/recent_login_username_cleanup_rule.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/model/recent_login_username_cache.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/extensions/list_recent_login_username_extension.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/model/recent_login_username.dart';
|
||||
|
||||
class RecentLoginUsernameCacheManager {
|
||||
class RecentLoginUsernameCacheManager extends CacheManagerInteraction {
|
||||
|
||||
final RecentLoginUsernameCacheClient _recentLoginUsernameCacheClient;
|
||||
|
||||
@@ -21,4 +25,71 @@ class RecentLoginUsernameCacheManager {
|
||||
await _recentLoginUsernameCacheClient.deleteMultipleItem(newListKeyRecent);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<RecentLoginUsername>> getAllRecentLoginUsernamesLatest({
|
||||
int? limit,
|
||||
String? pattern,
|
||||
}) async {
|
||||
final listRecentUsernameCache =
|
||||
await _recentLoginUsernameCacheClient.getAll();
|
||||
final listValidRecentUsername = listRecentUsernameCache
|
||||
.where((recentCache) =>
|
||||
_filterRecentLoginUsernameCache(recentCache, pattern))
|
||||
.map((recentCache) => recentCache.toRecentLoginUsername())
|
||||
.toList();
|
||||
|
||||
listValidRecentUsername.sortByCreationDate();
|
||||
|
||||
final newLimit = limit ?? 5;
|
||||
|
||||
return listValidRecentUsername.length > newLimit
|
||||
? listValidRecentUsername.sublist(0, newLimit)
|
||||
: listValidRecentUsername;
|
||||
}
|
||||
|
||||
Future<void> saveLoginUsername(
|
||||
RecentLoginUsername recentLoginUsername,
|
||||
) async {
|
||||
final isExist = await _recentLoginUsernameCacheClient.isExistItem(
|
||||
recentLoginUsername.username,
|
||||
);
|
||||
if (isExist) {
|
||||
await _recentLoginUsernameCacheClient.updateItem(
|
||||
recentLoginUsername.username,
|
||||
recentLoginUsername.toRecentLoginUsernameCache(),
|
||||
);
|
||||
} else {
|
||||
await _recentLoginUsernameCacheClient.insertItem(
|
||||
recentLoginUsername.username,
|
||||
recentLoginUsername.toRecentLoginUsernameCache(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
bool _filterRecentLoginUsernameCache(
|
||||
RecentLoginUsernameCache recentLoginUsernameCache,
|
||||
String? pattern,
|
||||
) {
|
||||
if (pattern == null || pattern.trim().isEmpty) {
|
||||
return true;
|
||||
} else {
|
||||
return recentLoginUsernameCache.matchUsername(pattern);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> clear() => _recentLoginUsernameCacheClient.clearAllData();
|
||||
|
||||
@override
|
||||
Future<void> migrateHiveToIsolatedHive() async {
|
||||
try {
|
||||
final legacyMapItems = await _recentLoginUsernameCacheClient.getMapItems(
|
||||
isolated: false,
|
||||
);
|
||||
log('$runtimeType::migrateHiveToIsolatedHive(): Length of legacyMapItems: ${legacyMapItems.length}');
|
||||
await _recentLoginUsernameCacheClient.insertMultipleItem(legacyMapItems);
|
||||
log('$runtimeType::migrateHiveToIsolatedHive(): ✅ Migrate Hive box "${_recentLoginUsernameCacheClient.tableName}" → IsolatedHive DONE');
|
||||
} catch (e) {
|
||||
logError('$runtimeType::migrateHiveToIsolatedHive(): ❌ Migrate Hive box "${_recentLoginUsernameCacheClient.tableName}" → IsolatedHive FAILED, Error: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,14 @@ import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/extensions/account_id_extensions.dart';
|
||||
import 'package:tmail_ui_user/features/caching/clients/recent_search_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/caching/interaction/cache_manager_interaction.dart';
|
||||
import 'package:tmail_ui_user/features/caching/utils/cache_utils.dart';
|
||||
import 'package:tmail_ui_user/features/cleanup/domain/model/recent_search_cleanup_rule.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/model/recent_search_cache.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/extensions/list_recent_search_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/model/recent_search.dart';
|
||||
|
||||
class RecentSearchCacheManager {
|
||||
class RecentSearchCacheManager extends CacheManagerInteraction {
|
||||
|
||||
static const int _defaultRecentSearchLimit = 10;
|
||||
|
||||
@@ -98,4 +99,20 @@ class RecentSearchCacheManager {
|
||||
return recentSearchCache.match(pattern);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> clear() => _recentSearchCacheClient.clearAllData();
|
||||
|
||||
@override
|
||||
Future<void> migrateHiveToIsolatedHive() async {
|
||||
try {
|
||||
final legacyMapItems = await _recentSearchCacheClient.getMapItems(
|
||||
isolated: false,
|
||||
);
|
||||
log('$runtimeType::migrateHiveToIsolatedHive(): Length of legacyMapItems: ${legacyMapItems.length}');
|
||||
await _recentSearchCacheClient.insertMultipleItem(legacyMapItems);
|
||||
log('$runtimeType::migrateHiveToIsolatedHive(): ✅ Migrate Hive box "${_recentSearchCacheClient.tableName}" → IsolatedHive DONE');
|
||||
} catch (e) {
|
||||
logError('$runtimeType::migrateHiveToIsolatedHive(): ❌ Migrate Hive box "${_recentSearchCacheClient.tableName}" → IsolatedHive FAILED, Error: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user