Skip to content

[Android] Make db size configurable #98

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

Closed
wants to merge 15 commits into from

Conversation

alexkuttig
Copy link
Contributor

Summary:

Since I do need a larger max db size, I added an optional size parameter to the package constructor. This makes the maximum db size configurable, while keeping the standard size of 6L * 1024L * 1024L when not giving any value. (like discussed in ##83)

new AsyncStoragePackage(100L * 1024L * 1024L)

Test Plan:

1.) create async storage in MainApplication.java of the test app with new AsyncStoragePackage()
2.) write > 6MB data to async storage
3.) change initialization of AsyncStorage in MainApplication.java to new AsyncStoragePackage(100L * 1024L * 1024L)
4.) write additional data

@tido64 tido64 added enhancement New feature or request platform: Android This is Android specific labels May 8, 2019
@krizzu krizzu changed the title made dataset size user configurable [Android] Make db size configurable May 9, 2019
@krizzu
Copy link
Member

krizzu commented May 9, 2019

Hey @alexkuttig, thanks for your input.

Like we pointed in discussion, Async Storage has been limited to 6MB by original authros, to avoid data loss (checkout this comment).

I believe this is a nice feature to have and use, if you know what potential consequences are.

We can go ahead and add it, but first, let's document it well. Can I ask you to do some more work here?

  1. Go to docs/ in this project
  2. Rename AdvancedUsage.md to BrownfieldIntegration.md
  3. Create Advanced directory
  4. Move BrownfieldIntegration.md to Advanced dir
  5. Create new doc file (call it, for example, IncreaseDbSize.md or something similar)
  6. Document your feature there - usage and potential consequences (you can quote original authors)

Let me know what you think.

thanks.

@alexkuttig
Copy link
Contributor Author

Hi @krizzu,

thanks for your feedback. I added the documentation for this feature. Feedback or change requests welcome :-)

Best,
Alex

Copy link
Member

@krizzu krizzu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

I've left my picky notes, please let me know what you think.

thanks.

@@ -0,0 +1,25 @@
# Increase AsyncStorage Database Size on Android

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd put here sections for platforms, i.e use H2 for Android and below iOS (which is not supported for now).

alexkuttig and others added 7 commits May 9, 2019 12:37
Co-Authored-By: Krzysztof Borowy <krizzu.dev@gmail.com>
Co-Authored-By: Krzysztof Borowy <krizzu.dev@gmail.com>
Co-Authored-By: Krzysztof Borowy <krizzu.dev@gmail.com>
Co-Authored-By: Krzysztof Borowy <krizzu.dev@gmail.com>
Co-Authored-By: Krzysztof Borowy <krizzu.dev@gmail.com>
Co-Authored-By: Krzysztof Borowy <krizzu.dev@gmail.com>
@alexkuttig
Copy link
Contributor Author

Thanks for your feedback! I added your request changes.

@krizzu
Copy link
Member

krizzu commented May 9, 2019

@alexkuttig Did you see my comment here?

@@ -59,7 +59,8 @@ getData = async () => {

```

See docs for [api and more examples](docs/API.md), and [brownfield integration guide](docs/AdvancedUsage.md).
### Advanced
See docs for [api and more examples](docs/API.md) or [advanced usages](docs/advanced).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the link here still correct?

@@ -18,12 +18,24 @@
import java.util.List;

public class AsyncStoragePackage implements ReactPackage {

long mSize = 6L * 1024L * 1024L;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private?

to

```
new AsyncStorage(100L * 1024L * 1024L)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bad practice to pass parameters to getPackages. It will also prevent autolinking available in RN 0.60 to work with this package. Please move the initialization logic to JS, something like:

// helpers/Storage.js
import {createAsyncStorage} from '@react-native-community/async-storage';
const AsyncStorage = createAsyncStorage(100 * 1024 * 1024);
export default AsyncStorage;

@krizzu
Copy link
Member

krizzu commented May 9, 2019

Thanks @thymikee for pointing this out. I spoke with @Salakar and he explained me what's happening with auto-linking. Although, I'm not happy with configuring DB size from JS (especially that it's one platform related), but I've got an idea on how to work around this (@Salakar's suggestion™).

@alexkuttig I'll come back to you with necessary changes we have to do in order to get it working on new auto-linking feature (which will be backward compatible).

thanks

@krizzu
Copy link
Member

krizzu commented May 10, 2019

@alexkuttig Auto-linking feature will not provide a way for devs to pass an argument to the Package constructor anymore (so we cannot pass new DB size like in your example). To work around this, let's use gradle to inject values in build time.

To get this working, we need to change where the default value comes from in ReactDatabaseSupplier.java, rest is handled in compile time.

I've implemented this in my fork.

So end user will just have to modify their gradle.properties to change size limit.

Let me know if you need any help.

thanks

@thymikee
Copy link

@krizzu @Salakar FYI I just realized (thanks to @grabbou finally providing documentation for the CLI config :P) that we have a dependency.platforms.android.packageInstance field (https://github.com/react-native-community/cli/blob/master/docs/dependencies.md#platformsandroidpackageinstance) for android that allows library maintainers to put custom variables to a constructor, that can be overriden in user's config dependencies['project-name'].platforms.android.packageInstance field (https://github.com/react-native-community/cli/blob/master/docs/projects.md#dependencies).

So technically this should be possible even though a bit cumbersome (and there are slight differences in configuration for pre RN 0.60). But still I wouldn't encourage such practices, it's more of an escape hatch for existing solutions. If the package can be zero or almost config, let's keep it that way.

@krizzu
Copy link
Member

krizzu commented May 10, 2019

@thymikee Like you said, this would be more cumbersome than just adding a value in gradle.properties, so I stray off from that path. Thanks from bringing this up tho 👍

@alexkuttig
Copy link
Contributor Author

Hey guys,

thanks for your feedback.
@krizzu that's a cool solution. How do we proceed? Do we just close this pull request and open yours, or should I change this one and add documentation for that feature?

@krizzu
Copy link
Member

krizzu commented May 10, 2019

@alexkuttig I don't want your contribution to get lost, so please make changes in your current PR or close this one and open new one with docs and new implementation.

Thanks.

@alexkuttig
Copy link
Contributor Author

Thats very kind of you. I made a new pull request (#99 )

@alexkuttig alexkuttig closed this May 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request platform: Android This is Android specific
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants