mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2026-02-12 03:04:45 +01:00
feat(database): Add database compression function (#1027)
* feat(database): Add database compression function Add database compression functionality to the connection statistics page to reduce the size of the database file Add multi-language support and related UI interactions * fix(database): Update the description of database compression operations and fix the statistics cleanup logic Update the description of database compression operations in the multilingual files to explicitly state that data will not be lost Fix the connection statistics cleanup logic to ensure correct matching of server IDs Add error handling for the compression operation to prevent the UI from freezing * Update lib/l10n/app_en.arb Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
@@ -225,6 +225,9 @@ class ServersNotifier extends _$ServersNotifier {
|
||||
Stores.setting.serverOrder.put(newOrder);
|
||||
Stores.server.delete(id);
|
||||
|
||||
// Remove connection stats when server is deleted
|
||||
Stores.connectionStats.clearServerStats(id);
|
||||
|
||||
// Remove SSH session when server is deleted
|
||||
final sessionId = 'ssh_$id';
|
||||
TermSessionManager.remove(sessionId);
|
||||
@@ -243,6 +246,7 @@ class ServersNotifier extends _$ServersNotifier {
|
||||
|
||||
Stores.setting.serverOrder.put([]);
|
||||
Stores.server.clear();
|
||||
Stores.connectionStats.clearAll();
|
||||
bakSync.sync(milliDelay: 1000);
|
||||
}
|
||||
|
||||
|
||||
@@ -182,9 +182,23 @@ class ConnectionStatsStore extends HiveStore {
|
||||
|
||||
// Clear stats for a specific server
|
||||
void clearServerStats(String serverId) {
|
||||
final keysToDelete = keys().where((key) => key.startsWith(serverId)).toList();
|
||||
final keysToDelete = keys().where((key) {
|
||||
if (key == serverId) return true;
|
||||
return key.startsWith('${serverId}_');
|
||||
}).toList();
|
||||
for (final key in keysToDelete) {
|
||||
remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> compact() async {
|
||||
Loggers.app.info('Start compacting connection_stats database...');
|
||||
try {
|
||||
await box.compact();
|
||||
Loggers.app.info('Finished compacting connection_stats database');
|
||||
} catch (e, st) {
|
||||
Loggers.app.warning('Failed compacting connection_stats database', e, st);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user