Skip to content

Commit

Permalink
[native] Temporary for Android failing to load large Redux store
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ashoat committed Apr 30, 2021
1 parent b1f4ab9 commit 0139a49
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions native/android/app/src/main/java/org/squadcal/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import androidx.multidex.MultiDexApplication;
import android.content.Context;

import android.database.CursorWindow;

import org.unimodules.adapters.react.ModuleRegistryAdapter;
import org.unimodules.adapters.react.ReactModuleRegistryProvider;
import org.unimodules.core.interfaces.SingletonModule;
Expand All @@ -28,6 +30,7 @@
import java.util.Arrays;
import java.util.List;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Field;
import java.security.Security;

public class MainApplication extends MultiDexApplication implements ReactApplication {
Expand Down Expand Up @@ -77,6 +80,15 @@ public void onCreate() {
Security.insertProviderAt(new org.conscrypt.OpenSSLProvider(), 1);
SoLoader.init(this, /* native exopackage */ false);
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
try {
Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize");
field.setAccessible(true);
field.set(null, 100 * 1024 * 1024); // 100 MiB
} catch (Exception e) {
if (BuildConfig.DEBUG) {
e.printStackTrace();
}
}
}

/**
Expand Down

0 comments on commit 0139a49

Please sign in to comment.