From 0139a49528e748a640f859136c2b49c5685da892 Mon Sep 17 00:00:00 2001 From: Ashoat Tevosyan Date: Wed, 28 Apr 2021 22:33:05 -0400 Subject: [PATCH] [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](https://github.com/react-native-async-storage/async-storage/issues/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](https://github.com/rt2zz/redux-persist/issues/1265#issuecomment-742704826) 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](https://github.com/react-native-async-storage/async-storage/pull/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 --- .../src/main/java/org/squadcal/MainApplication.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/native/android/app/src/main/java/org/squadcal/MainApplication.java b/native/android/app/src/main/java/org/squadcal/MainApplication.java index 917becefe4..6841192b94 100644 --- a/native/android/app/src/main/java/org/squadcal/MainApplication.java +++ b/native/android/app/src/main/java/org/squadcal/MainApplication.java @@ -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; @@ -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 { @@ -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(); + } + } } /**