Skip to content

Commit 0139a49

Browse files
committed
[native] Temporary for Android failing to load large Redux store
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
1 parent b1f4ab9 commit 0139a49

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

native/android/app/src/main/java/org/squadcal/MainApplication.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import androidx.multidex.MultiDexApplication;
66
import android.content.Context;
77

8+
import android.database.CursorWindow;
9+
810
import org.unimodules.adapters.react.ModuleRegistryAdapter;
911
import org.unimodules.adapters.react.ReactModuleRegistryProvider;
1012
import org.unimodules.core.interfaces.SingletonModule;
@@ -28,6 +30,7 @@
2830
import java.util.Arrays;
2931
import java.util.List;
3032
import java.lang.reflect.InvocationTargetException;
33+
import java.lang.reflect.Field;
3134
import java.security.Security;
3235

3336
public class MainApplication extends MultiDexApplication implements ReactApplication {
@@ -77,6 +80,15 @@ public void onCreate() {
7780
Security.insertProviderAt(new org.conscrypt.OpenSSLProvider(), 1);
7881
SoLoader.init(this, /* native exopackage */ false);
7982
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
83+
try {
84+
Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize");
85+
field.setAccessible(true);
86+
field.set(null, 100 * 1024 * 1024); // 100 MiB
87+
} catch (Exception e) {
88+
if (BuildConfig.DEBUG) {
89+
e.printStackTrace();
90+
}
91+
}
8092
}
8193

8294
/**

0 commit comments

Comments
 (0)