mode
- Skip automatic compaction when `data.mdb` is 10GB or larger, and
surface an in-app notification instead of surprising users with a long
startup wait
- Keep manual compaction available for large databases by tracking
whether a next-launch compaction request was scheduled automatically
or explicitly by the user
- Add a large-database explanation to the compaction loading screen to
clarify that long runtimes are expected for oversized databases and
are usually a one-time catch-up cost
- Add a developer-only `Every minute` auto-compact schedule to make
rollout and reminder behavior easier to test locally
- Add and update unit tests covering large-database auto-compaction
skips, request-source persistence, reminder scheduling, and the
developer testing interval
Motivation:
TestFlight users with long-lived databases were hitting the brand-new
compaction flow for the first time, which could turn startup into a
multi-minute wait. These changes make automatic compaction less
disruptive for very large databases, preserve an explicit manual path
for users who want to optimize immediately, and add a fast
developer-only schedule to make the new behavior easier to validate
during testing.
This is an enhancement for an unreleased feature, so therefore no
changelog is needed.
Closes: https://github.com/damus-io/damus/issues/3730
Changelog-None
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Introduce CompactionView and CompactionLoadingView to schedule and run
Ndb compaction on a background task before showing the main UI. Replace
the direct compaction calls in ContentView and make CompactionView the
app's launch entry so startup compaction presents a loading UI and
avoids blocking the main thread.
Changelog-Fixed: Fixed startup crash when app performs long-running
compaction procedure
Closes: #3726
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Also clean up temp directory on post-replace size mismatch to match
all other error paths in compact_if_needed.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add `compact(to:)` method on `Ndb` using `mdb_env_copy2` / `ndb_snapshot`
with `MDB_CP_COMPACT` flag to produce a smaller compacted database copy
- Add `compact_if_needed(db_path:)` static startup method that reads a
UserDefaults flag, opens a temp Ndb, compacts to a sibling temp dir,
atomically replaces `data.mdb`, cleans up, and clears the flag
- Add `set_compact_on_next_launch()` to schedule compaction from the UI
- Call `Ndb.compact_if_needed()` in `ContentView.connect()` before the
main Ndb instance is opened
- Add `CompactDatabaseButton` to `StorageSettingsView` with a confirmation
dialog that informs the user a restart is needed
- Add `NdbCompactionTests` unit tests covering flag API, no-op path,
missing-DB path, and full round-trip compaction
Closes: https://github.com/damus-io/damus/issues/3680
Changelog-Added: Added "Compact Database" button in Settings → Storage that reclaims unused space by compacting the NostrDB on the next app launch
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>