feat(database): Add database compression function#1027
feat(database): Add database compression function#1027GT-610 merged 3 commits intolollipopkit:mainfrom
Conversation
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
📝 WalkthroughWalkthroughAdds a database compaction operation to ConnectionStatsStore, exposes a UI flow to trigger compaction with size reporting, clears connection stats when servers are deleted, and adds localization strings for the compaction UI across multiple locales. Changes
Sequence DiagramsequenceDiagram
actor User
participant UI as Connection Stats Page
participant Store as ConnectionStatsStore
participant Hive as Hive Box
participant FS as File System
User->>UI: Tap compact icon
UI->>FS: Read DB file size (connection_stats_enc.hive)
UI->>User: Show confirmation dialog with size
User->>UI: Confirm
UI->>UI: Close dialog, set _isCompacting = true
UI->>Store: compact()
Store->>Store: Log compaction start
Store->>Hive: box.compact()
Hive->>FS: Rebuild/optimize storage
FS-->>Hive: Compaction done
Hive-->>Store: Return success
Store->>Store: Log compaction end
Store-->>UI: return
UI->>FS: Re-read DB file size
UI->>UI: Clear _isCompacting, show snackbar with size delta
UI-->>User: Display result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✏️ Tip: You can disable this entire section by setting Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 8
🤖 Fix all issues with AI agents
In `@lib/data/provider/server/all.dart`:
- Around line 228-229: clearServerStats currently removes keys using
startsWith(serverId) which can delete unintended keys like "abc1"; update
Stores.connectionStats.clearServerStats to only match the serverId as a distinct
segment (for example require a delimiter such as `${serverId}_` or split the key
on '_' and compare the first segment exactly) so only keys belonging to that
server are cleared; locate the clearServerStats implementation and replace the
startsWith check with a delimiter-aware or segment comparison approach and
ensure callers (e.g., the deletion call in all.dart) keep using clearServerStats
unchanged.
In `@lib/l10n/app_de.arb`:
- Around line 49-50: The German locale is missing the l10n key "confirm" used by
the UI; add the key "confirm" with the appropriate German translation (e.g.,
"Bestätigen") to app_de.arb alongside the existing keys like "compactDatabase"
and "compactDatabaseContent" so the key name exactly matches the English source
(l10n.confirm) and keeps locales in sync for gen-l10n.
In `@lib/l10n/app_en.arb`:
- Around line 49-51: The string value for the localization key
"compactDatabaseContent" contains a typo ("shole") — update the value to replace
"shole" with "whole" so it reads "This will rebuild the whole database to reduce
file size." Ensure you only edit the value for "compactDatabaseContent"
(preserve the placeholder {size} and surrounding newlines) to avoid breaking
other keys.
In `@lib/l10n/app_nl.arb`:
- Line 50: The string value for the localization key "compactDatabaseContent"
contains a typo: change "Databasgrootte" to "Databasegrootte" so the Dutch reads
correctly; update the value associated with compactDatabaseContent to use
"Databasegrootte: {size}\n\nDit zal de hele database herbouwen om de
bestandsgrootte te verkleinen." ensuring only the typo is corrected and
escaping/newline formatting remains unchanged.
In `@lib/l10n/app_pt.arb`:
- Around line 49-50: You added the localization keys "compactDatabase" and
"compactDatabaseContent" in app_pt.arb but did not regenerate the Flutter
localization artifacts; run the localization generator by executing `flutter
gen-l10n` (or your project's configured l10n build command) to refresh generated
classes and arb translations, then include the updated generated files in the
commit so consumers of the new keys (e.g., the generated Localizations class and
lookup maps) are up to date.
In `@lib/l10n/app_ru.arb`:
- Around line 49-50: The Russian locale file is missing the "confirm" message
used by the UI (referenced as l10n.confirm in
lib/view/page/server/connection_stats.dart); add a "confirm" key and appropriate
Russian translation to lib/l10n/app_ru.arb (matching the base locale key name
"confirm") so gen-l10n sees the key in all locales and the code can access
l10n.confirm without errors.
In `@lib/view/page/server/connection_stats.dart`:
- Around line 222-231: The compaction call (Stores.connectionStats.compact())
can throw and currently skips resetting _isCompacting and surfacing errors; wrap
the await Stores.connectionStats.compact() and subsequent file-size logic in
try-catch-finally, catch exceptions and call context.showSnackBar(...) with the
error message (or libL10n failure text) to surface failures, and in finally
ensure if (mounted) setState(() => _isCompacting = false) so the spinner is
always cleared; keep existing context.pop() and mounted checks around UI updates
(sizeStr/newSizeStr) but move them into the try/finally blocks around the
compact call.
- Line 21: The compact button should be disabled while _isCompacting is true to
prevent concurrent dialog invocations: update the compact button's onPressed to
return null when _isCompacting is true (e.g., onPressed: _isCompacting ? null :
() => _startCompaction()), and ensure the compaction routine around the dialog
sets _isCompacting = true via setState before awaiting the async work/dialog and
sets _isCompacting = false in a finally block (also via setState) so the button
is re-enabled when done; refer to the _isCompacting field and the compact
button's onPressed handler to make these changes.
🧹 Nitpick comments (3)
lib/data/store/connection_stats.dart (1)
191-194: Add error handling around Hive compaction to surface failures.
box.compact()can throwHiveErrorduring async writes (e.g., I/O failures or incorrect lifecycle state). Currently, failures will bubble uncaught. Wrap in try/catch to log the error and rethrow so the UI can report the failure gracefully.♻️ Proposed refactor
Future<void> compact() async { Loggers.app.info('Start compacting connection_stats database...'); - await box.compact(); - Loggers.app.info('Finished 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; + } }lib/l10n/app_en.arb (1)
49-51: Regenerate localization after ARB updates.Please run
flutter gen-l10nto update generated localization files after these ARB changes. As per coding guidelines, ...lib/view/page/server/connection_stats.dart (1)
210-237: Keep dialog actions in the extension for separation of concerns.For consistency with the other dialog helpers, move
_showCompactDialoginto the existing extension below. Based on learnings, ...
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (13)
lib/generated/l10n/l10n.dartis excluded by!**/generated/**lib/generated/l10n/l10n_de.dartis excluded by!**/generated/**lib/generated/l10n/l10n_en.dartis excluded by!**/generated/**lib/generated/l10n/l10n_es.dartis excluded by!**/generated/**lib/generated/l10n/l10n_fr.dartis excluded by!**/generated/**lib/generated/l10n/l10n_id.dartis excluded by!**/generated/**lib/generated/l10n/l10n_ja.dartis excluded by!**/generated/**lib/generated/l10n/l10n_nl.dartis excluded by!**/generated/**lib/generated/l10n/l10n_pt.dartis excluded by!**/generated/**lib/generated/l10n/l10n_ru.dartis excluded by!**/generated/**lib/generated/l10n/l10n_tr.dartis excluded by!**/generated/**lib/generated/l10n/l10n_uk.dartis excluded by!**/generated/**lib/generated/l10n/l10n_zh.dartis excluded by!**/generated/**
📒 Files selected for processing (16)
lib/data/provider/server/all.dartlib/data/store/connection_stats.dartlib/l10n/app_de.arblib/l10n/app_en.arblib/l10n/app_es.arblib/l10n/app_fr.arblib/l10n/app_id.arblib/l10n/app_ja.arblib/l10n/app_nl.arblib/l10n/app_pt.arblib/l10n/app_ru.arblib/l10n/app_tr.arblib/l10n/app_uk.arblib/l10n/app_zh.arblib/l10n/app_zh_tw.arblib/view/page/server/connection_stats.dart
🧰 Additional context used
📓 Path-based instructions (4)
lib/l10n/**/*.arb
📄 CodeRabbit inference engine (CLAUDE.md)
lib/l10n/**/*.arb: After modifying ARB files, run: flutter gen-l10n to regenerate localization
Keep localized strings in ARB files under lib/l10n/ (Flutter i18n)
Files:
lib/l10n/app_uk.arblib/l10n/app_zh.arblib/l10n/app_de.arblib/l10n/app_pt.arblib/l10n/app_fr.arblib/l10n/app_zh_tw.arblib/l10n/app_nl.arblib/l10n/app_ru.arblib/l10n/app_id.arblib/l10n/app_ja.arblib/l10n/app_tr.arblib/l10n/app_en.arblib/l10n/app_es.arb
lib/data/provider/**/*.dart
📄 CodeRabbit inference engine (CLAUDE.md)
Organize Riverpod providers by feature under lib/data/provider/
Files:
lib/data/provider/server/all.dart
lib/view/**/*.dart
📄 CodeRabbit inference engine (CLAUDE.md)
lib/view/**/*.dart: Prefer widgets/utilities from fl_lib for common UI (e.g., CustomAppBar, context.showRoundDialog, Input, Btnx.cancelOk)
Prefer using libL10n strings before adding new ones to project l10n
Split UI into build, actions, and utils; use extension on to separate concerns
Files:
lib/view/page/server/connection_stats.dart
lib/data/store/**/*.dart
📄 CodeRabbit inference engine (CLAUDE.md)
Persist state using Hive stores placed under lib/data/store/
Files:
lib/data/store/connection_stats.dart
🧠 Learnings (6)
📚 Learning: 2025-10-08T09:36:41.682Z
Learnt from: CR
Repo: lollipopkit/flutter_server_box PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-10-08T09:36:41.682Z
Learning: Applies to lib/l10n/**/*.arb : Keep localized strings in ARB files under lib/l10n/ (Flutter i18n)
Applied to files:
lib/l10n/app_uk.arblib/l10n/app_zh.arblib/l10n/app_pt.arblib/l10n/app_fr.arblib/l10n/app_ru.arblib/l10n/app_id.arblib/l10n/app_tr.arb
📚 Learning: 2025-10-08T09:36:41.682Z
Learnt from: CR
Repo: lollipopkit/flutter_server_box PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-10-08T09:36:41.682Z
Learning: Applies to lib/data/model/server/**/*.dart : Place server management models under lib/data/model/server/
Applied to files:
lib/data/provider/server/all.dart
📚 Learning: 2025-10-08T09:36:41.682Z
Learnt from: CR
Repo: lollipopkit/flutter_server_box PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-10-08T09:36:41.682Z
Learning: Applies to lib/view/**/*.dart : Prefer widgets/utilities from fl_lib for common UI (e.g., CustomAppBar, context.showRoundDialog, Input, Btnx.cancelOk)
Applied to files:
lib/view/page/server/connection_stats.dart
📚 Learning: 2025-10-08T09:36:41.682Z
Learnt from: CR
Repo: lollipopkit/flutter_server_box PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-10-08T09:36:41.682Z
Learning: Applies to lib/view/**/*.dart : Prefer using libL10n strings before adding new ones to project l10n
Applied to files:
lib/view/page/server/connection_stats.dart
📚 Learning: 2025-10-08T09:36:41.682Z
Learnt from: CR
Repo: lollipopkit/flutter_server_box PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-10-08T09:36:41.682Z
Learning: Applies to lib/view/**/*.dart : Split UI into build, actions, and utils; use extension on to separate concerns
Applied to files:
lib/view/page/server/connection_stats.dart
📚 Learning: 2025-10-08T09:36:41.682Z
Learnt from: CR
Repo: lollipopkit/flutter_server_box PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-10-08T09:36:41.682Z
Learning: Applies to lib/data/store/**/*.dart : Persist state using Hive stores placed under lib/data/store/
Applied to files:
lib/data/store/connection_stats.dart
🔇 Additional comments (10)
lib/l10n/app_tr.arb (1)
49-50: LGTM!The Turkish localization entries for the database compaction feature are correctly added with proper placeholder usage (
{size}). The translations align well with the feature's purpose.As per coding guidelines, remember to run
flutter gen-l10nto regenerate localization files after these changes.lib/l10n/app_zh_tw.arb (1)
49-50: LGTM!The Traditional Chinese localization entries are well-translated and consistent with the feature's purpose. The placeholder
{size}is correctly preserved.lib/l10n/app_ja.arb (1)
49-50: LGTM!The Japanese localization entries are accurately translated and maintain proper placeholder usage for the database size parameter.
lib/l10n/app_fr.arb (1)
49-50: LGTM!The French localization entries are well-translated with proper grammar and correct placeholder preservation.
lib/l10n/app_id.arb (1)
49-50: LGTM!The Indonesian localization entries are correctly added with proper placeholder usage for the database compaction feature.
lib/l10n/app_zh.arb (1)
49-51: LGTM for the new localization entries.Strings are consistent with the compaction flow and placeholders.
lib/l10n/app_uk.arb (1)
49-50: LGTM for the new localization entries.lib/data/provider/server/all.dart (1)
249-249: Good cleanup of stats on bulk delete.lib/l10n/app_es.arb (1)
49-50: LGTM for the new localization entries.lib/view/page/server/connection_stats.dart (1)
1-1: LGTM —dart:ioimport is needed for file size checks.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
…ons 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
|
@coderabbitai So the last nitpick comments are not valid. |
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
|
Tip For best results, initiate chat on the files or code changes.
I appreciate you taking the time to explain the reasoning—keeping it consistent with |
Solve the database bloat issue by rebuilding
connection_stats_enc.hive.Resolve #924.
Summary by CodeRabbit
New Features
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.