Repository navigation
feat(storage): use NitroSQLite 10.2 connections and statements - #851
chrispader wants to merge 17 commits into
Conversation
1a8b643 to
1fa8054
Compare
|
@chrispader Is this ready for review? Held off looking at it since it has WIP in the title |
@inimaga not yet! I'll ping you once this is ready 🙌🏼 |
|
@inimaga this is ready for review! also cc @fabioh8010 so you can include this in your Onyx improvements list 🙌🏼 |
|
Thanks! I would like to review this one too 😄 |
fabioh8010
left a comment
There was a problem hiding this comment.
@chrispader I would appreciate if you could perform some performance measurements with this change (base with store-based solution vs this PR) over the main metrics and flows for Native. We need to make sure performance impact is verified.
Also, would be good to have more extensive test steps/QA testing here as it affects the whole app.
|
Chris's AI crew member here. 🤖 Following up on Fabio's review, I expanded the manual test steps here and in App #102422 and Mobile-Expensify #14179. They now cover High Traffic accounts, existing and fresh installations, chat history, expenses, tasks, profile changes, offline persistence, reconnects, and account switching. App pins Onyx commit |
|
Also cc for review @NicolasBonet @ikevin127 since Melvin assigned you on the corresponding issue too 🙌🏼 |
|
@fabioh8010 i'm working on the benchmarks now! |
|
@chrispader That's all from me on code-review, (7) comments ☝️ |
|
I will wait for Chris to check @ikevin127 's review before I review again |
|
Thanks for addressing my first-pass comments, I'm doing another pass 🔄 |
| independentReader.execute('PRAGMA busy_timeout=2000;'); | ||
| getItemStatement = independentReader.prepare('SELECT record_key, valueJSON FROM keyvaluepairs WHERE record_key = ?;'); | ||
| readStore = independentReader; | ||
| } catch { |
There was a problem hiding this comment.
lib/storage/providers/SQLiteProvider.ts line 182
🟡 This fallback is silent now. If reader setup fails on some devices in production, we quietly lose the main benefit of this PR (reads that don't queue behind writes), and neither telemetry nor the requested benchmarks can tell. IDBKeyValProvider/createStore.ts already logs similar connection events with Logger.logInfo.
Can we do the same here ?
import * as Logger from '../../Logger'; } catch (error) {
// SQLite can report failures on first use, so protect all reader setup.
Logger.logInfo(`SQLite independent reader unavailable, reading through the writer. Error: ${error instanceof Error ? error.message : String(error)}`);| export {NitroSQLiteError, NitroSQLiteExceptionType} from 'react-native-nitro-sqlite'; | ||
| } | ||
|
|
||
| declare module 'react-native-nitro-sqlite/mock' { |
There was a problem hiding this comment.
lib/types/modules/react-native-nitro-sqlite.d.ts line 6
🟡 This block copies NitroSQLite's shipped declarations by hand. The Pick<NitroSQLiteConnection, 'close' | 'delete' | ...> list is identical to the upstream lib/typescript/commonjs/mock/MockConnection.d.ts, and open, NitroSQLite and resetAllDatabases match lib/typescript/commonjs/mock.d.ts.
When upstream changes the mock, this copy drifts without any error. Legacy Node resolution ignores exports, so it should resolve the physical declaration file.
Could we re-export it, the same way the /errors block re-exports ?
declare module 'react-native-nitro-sqlite/mock' {
export * from 'react-native-nitro-sqlite/lib/typescript/commonjs/mock';
}| @@ -0,0 +1,9 @@ | |||
| # Changelog | |||
|
|
|||
| ## Unreleased | |||
There was a problem hiding this comment.
CHANGELOG.md line 3
🟡 The repo had no changelog before this PR, and the publish workflow (Expensify/GitHub-Actions npmPublish.yml) runs npm version patch on merge. So this ships as 3.0.120 under an ## Unreleased heading that nothing will ever rename.
A consumer on ^3.0.x with NitroSQLite 9.x still fails dependency resolution on a patch update, and never sees this note. Can we confirm with the Onyx maintainers (@inimaga, @fabioh8010) whether this release should get a manual minor bump or a GitHub release note instead ?
If neither, I'd drop the file rather than start a convention nobody maintains.
|
@chrispader That's it from me - ready after these 3 items:
Merge separately waits on Fabio's benchmarks 🙌 |
Onyx's SQLite provider shares one connection for reads and writes and prepares single-key queries on every call. I updated it to use NitroSQLite 10.2's independent reader and reusable statements while preserving read-after-write ordering and the stored JSON format.
Details
The native provider now requires NitroSQLite
^10.2.0, so native apps must upgrade and rebuild. The peer remains optional for other storage providers.The reader uses a bounded cache and a two-second lock timeout. If reader setup fails, reads use the writer; primary database-open failures retain the memory fallback. Repeated initialization preserves the active connections and queued writes, and chunked reads share one transaction snapshot.
Related Issues
Expensify/App#102424
Linked E/App PR
Expensify/App#102422
Automated Tests
SQLite provider tests use the published NitroSQLite mock and cover statement reuse, write ordering, snapshot consistency, batch rollback, JSON merges, reader setup failures, error classification, and repeated initialization.
Manual Tests
Author Checklist
I linked the correct issue in the
### Fixed Issuessection aboveI wrote clear testing steps that cover the changes made in this PR
TestssectionOffline stepssectionQA stepssection### Related Issuessection aboveI linked the corresponding Expensify/App PR in the
### Linked E/App PRsection above, and verified this change against it (E/App CI passed and manual testing completed)I wrote clear testing steps that cover the changes made in this PR
TestssectionI included screenshots or videos for tests on all platforms
I ran the tests on all platforms & verified they passed on:
I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
I followed proper code patterns (see Reviewing the code)
toggleReportand notonIconClick).myBool && <MyComponent />.STYLE.md) were followedIf a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
I followed the guidelines as stated in the Review Guidelines
I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like
Avatar, I verified the components usingAvatarare working as expected)I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
I verified that if a function's arguments changed that all usages have also been updated correctly
If a new component is created I verified that:
/** comment above it */thisproperly so there are no scoping issues (i.e.onClick={this.toggleReport}should be bound in the constructor).thisare necessary to be bound (i.e. avoid unnecessary binds)If any new file was added I verified that:
If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like
Avataris modified, I verified thatAvataris working as expected in all cases)If the
mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
I included screenshots or videos for tests on all platforms
I ran the tests on all platforms & verified they passed on:
I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
I followed proper code patterns (see Reviewing the code)
If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
I followed the guidelines as stated in the Review Guidelines
I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like
Avatar, I verified the components usingAvatarare working as expected)If a new CSS style is added I verified that:
StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))If new assets were added or existing ones were modified, I verified that:
npm run compress-svg)If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like
Avataris modified, I verified thatAvataris working as expected in all cases)If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
Designlabel and/or tagged@Expensify/designso the design team can review the changes.I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
If the
mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Verify that no errors appear in the JS console
Verify that no errors appear in the JS console
I verified any copy / text that was added to the app is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
If the PR adds or modifies the UI:
Screenshots/Videos
No screenshots or videos are included because this storage-provider change has no visible UI.