Move DB compaction to CompactionView

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>
This commit is contained in:
Daniel D’Aquino
2026-04-23 19:02:01 -07:00
parent 5cb8a495b5
commit 0d2f55f4e3
6 changed files with 244 additions and 26 deletions
+8 -8
View File
@@ -56,8 +56,8 @@ final class NdbCompactionTests: XCTestCase {
// Given: the flag is false (set in setUp)
let dbPath = testDirectory.path
// When
Ndb.compact_if_needed(db_path: dbPath)
// When / Then
XCTAssertNoThrow(try Ndb.compact_if_needed(db_path: dbPath))
// Then: no temp directory was created, no files were touched
let tempPath = "\(dbPath)/ndb_compact_temp"
@@ -79,8 +79,8 @@ final class NdbCompactionTests: XCTestCase {
let emptyPath = testDirectory.appendingPathComponent("empty_db").path
try? FileManager.default.createDirectory(atPath: emptyPath, withIntermediateDirectories: true)
// When
Ndb.compact_if_needed(db_path: emptyPath)
// When / Then
XCTAssertNoThrow(try Ndb.compact_if_needed(db_path: emptyPath))
// Then: flag is cleared, no temp directory left over
XCTAssertFalse(
@@ -112,8 +112,8 @@ final class NdbCompactionTests: XCTestCase {
Ndb.set_compact_on_next_launch()
// When
Ndb.compact_if_needed(db_path: dbPath)
// When / Then
XCTAssertNoThrow(try Ndb.compact_if_needed(db_path: dbPath))
// Then: the flag is cleared
XCTAssertFalse(
@@ -157,7 +157,7 @@ final class NdbCompactionTests: XCTestCase {
// When: compact_if_needed runs
Ndb.set_compact_on_next_launch()
Ndb.compact_if_needed(db_path: dbPath)
XCTAssertNoThrow(try Ndb.compact_if_needed(db_path: dbPath))
// Then: lock.mdb should NOT exist (it was deleted during compaction)
XCTAssertFalse(
@@ -279,7 +279,7 @@ final class NdbCompactionTests: XCTestCase {
Ndb.set_compact_on_next_launch()
let beforeCompact = Date()
Ndb.compact_if_needed(db_path: dbPath)
XCTAssertNoThrow(try Ndb.compact_if_needed(db_path: dbPath))
let afterCompact = Date()
guard let lastDate = Ndb.get_last_compact_date() else {