Skip to content

Commit

Permalink
feat: Allow to get data larger than 2MB in AsyncStorage
Browse files Browse the repository at this point in the history
Default Android cursor size is 2MB so we can not store entries larger
than 2MB by default. But backup feature store quickly more than 2MB.

There are two main possibilities :
- AsyncStorage recommand to separate data in multiple entries and use
multiGet and multiSet
- increase sCursorWindowSize in MainApplication.java

I try here the second way now which looks like the "easy quick fix".

50MB seems a reasonable value here. 1000 pictures in mediasToBackup ~
330KiB

See
react-native-async-storage/async-storage#617 (comment)
and
https://react-native-async-storage.github.io/async-storage/docs/limits
  • Loading branch information
zatteo committed Nov 13, 2023
1 parent 2241606 commit 8a518c5
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import io.cozy.flagship.mobile.httpserver.HttpServerPackage;
import io.cozy.flagship.mobile.webview.WebViewPackage;

import android.database.CursorWindow;
import java.lang.reflect.Field;

public class MainApplication extends Application implements ReactApplication {

private final ReactNativeHost mReactNativeHost =
Expand Down Expand Up @@ -61,6 +64,16 @@ public void onCreate() {
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
WebView.setWebContentsDebuggingEnabled(true);
OkHttpClientProvider.setOkHttpClientFactory(new UserAgentClientFactory());

try {
Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize");
field.setAccessible(true);
field.set(null, 50 * 1024 * 1024); // 50MB
} catch (Exception e) {
if (BuildConfig.DEBUG) {
e.printStackTrace();
}
}
}

/**
Expand Down

0 comments on commit 8a518c5

Please sign in to comment.