Safely apply OTA DB updates: reuse live DB handle, use native download, and reorganize app init#1535
Conversation
|
Closing. Two structural issues:
The defer-OTA idea was evaluated in #1533 and closed — it cannot be implemented as-is because the DB is always open after startup, which would mean updates never fire. Long-term direction (defer-to-cold-start architecture) is documented as Option B in #1532's TODO block. For the build-21 crash we're waiting on Sentry data or adding a native-exception diagnostic before the next build. Shipping speculative fixes without knowing what broke would burn EAS credits without informing the diagnosis. |
Motivation
Description
App.tsxby extractinghydrateAppState()and calling it only after content DB initialization, and setdbStatusearly wheninitDatabase()returnsneeds_download.DbDownloadScreenonCompleteto beasync-capable and await post-download initialization steps (initDatabase,initUserDatabase, Sentry anon id set, store hydrations, andpruneEvents) before settingdbStatustoready.getDbIfInitialized()andcloseDatabaseConnection()helpers insrc/db/database.tsto expose/close the live content DB handle without forcing open/close churn.services/ContentUpdater.tsadded an early check usinggetDbIfInitialized()to defer OTA applies when a live DB handle is open, reused the live handle insidegetInstalledVersion()to avoid opening a second connection, switched full-DB downloads toFile.downloadFileAsync, and replaced the memory-heavy file checksum step with validation that opens the downloaded DB and checksdb_meta.content_hashplusPRAGMA integrity_checkbefore swapping files.__tests__/services/ContentUpdater.test.tsto mock nativedownloadFileAsync, introducemockGetDbIfInitialized, and add tests covering live-handle reuse/deferral, native download usage, integrity-check failure, and adjusted download progress expectations while removing the legacy chunked-write assertions.Testing
jestunit test suite for the ContentUpdater service (__tests__/services/ContentUpdater.test.ts) which exercises manifest fetching, delta/full update flows, and the new live-DB and native-download paths, and the tests passed.ContentUpdatertests asserting the native download, deferral when live DB is open, and integrity-check behavior all succeed under the updated mocks.Codex Task