Add NdbCompactionProgress and Step with user-facing titles/details,
and a progress callback to Ndb.compact_if_needed to emit stage updates.
Refactor CompactionView to a single CompactionState and render linear
progress, step title/detail and percentage. Ensure UI updates happen on
the MainActor and surface errors/completion cleanly.
Changelog-None
Closes: https://github.com/damus-io/damus/issues/3730
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>