-
Notifications
You must be signed in to change notification settings - Fork 473
feat(android): Use Room library for persistent storage #528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ec73170
to
69a6c95
Compare
android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncStorageModule.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I haven't tested it yet. I'll try to find some time to do so but will tentatively approve in the meantime. 😄
android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncStorageModule.java
Show resolved
Hide resolved
android/src/main/java/com/reactnativecommunity/asyncstorage/next/ArgumentHelpers.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/reactnativecommunity/asyncstorage/next/ErrorHelpers.kt
Show resolved
Hide resolved
android/src/test/java/com/reactnativecommunity/asyncstorage/next/StorageTest.kt
Show resolved
Hide resolved
Functionality to persist data, new example, error handling
249dfbd
to
a62ce70
Compare
a62ce70
to
baa5e6c
Compare
27ed528
to
a74d613
Compare
86114f9
to
b388e87
Compare
b388e87
to
70de3b0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
🎉 This PR is included in version 1.15.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary: Android wasn't persisting the Redux store when logged in with the "ashoat" user. I saw the "Row too big to fit into CursorWindow" error, so I Googled around and found this hack in a [GitHub issue](react-native-async-storage/async-storage#537). The long-term fix is for us to move the database stuff to SQLite. For completeness, here are some other fixes I considered: 1. [react-native-mmkv](https://github.com/mrousavy/react-native-mmkv) as storage for `redux-persist` (not confident it will handle huge pages better though) 2. [Separating reducers](rt2zz/redux-persist#1265 (comment)) into distinct `AsyncStorage` keys (not sure what the distribution of size by keys is, and might require a migration) 3. Upgrading `AsyncStorage` and investing [this](https://react-native-async-storage.github.io/async-storage/docs/advanced/db_size) (people on the issue said it didn't help) 4. [Moving](react-native-async-storage/async-storage#528) off of SQLite storage onto Android Room storage (people on the issue said it didn't help) I think using this hack for now is a good stopgap. Test Plan: Make sure Android is loading the persisted store correctly when the app starts Reviewers: palys-swm Reviewed By: palys-swm Subscribers: KatPo, Adrian, atul Differential Revision: https://phabricator.ashoat.com/D1069
Summary
Current implementation of Sqlite access is cumbersome, error prone and produces some hard to reproduce errors to users. This PR aims to improve our native implementation of SQLite access and thread control.
About
This PR introduced the "next" storage implementation. Room has been used for database access, and Coroutines to handle asynchronous work.
I tried to reuse old database file, but due to it having a SQLite bug (where
primary key
can be null, which is a SQLite violation that Room is guarded against) I had to provide a migration path to copy over values to new database. This operation is done only once, the very first time feature is switched on.No developer migration is necessary to start using this feature. It means that, once switched on, the same data stored so far will be available to use. No API change on JS side is involved. One notable change that can be somehow breaking is how this feature handle AsyncStorage rules violation - if
key
used is not string (or null) ORvalue
is not a string, then error with proper message is thrown. No more cryptic sqlite errors.As part of this PR and feature, some new enhancement:
Test plan
Green CI, manual test on the Example App.