Skip to content

Data structure best-practice: multiple key/values or one big JSON? #320

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
stazrad opened this issue Mar 28, 2020 · 2 comments
Closed

Data structure best-practice: multiple key/values or one big JSON? #320

stazrad opened this issue Mar 28, 2020 · 2 comments
Labels
question General question about usage

Comments

@stazrad
Copy link

stazrad commented Mar 28, 2020

You want to:

Are there best practices when it comes to storing app data locally? If possible, I'd prefer to store all of it in one JSON object under a key like AppData or something and just mutate this object and store it.

Details:

Is this an acceptable practice or should it be a series of individual key/values? Is there a max length allowed for the strings that can be stored under a single key? Will this be throttled at scale? I'd appreciate the insight form anyone who has tried this!

@krizzu krizzu added bug Something isn't working question General question about usage labels Mar 31, 2020
@krizzu
Copy link
Member

krizzu commented Mar 31, 2020

Hey @webbhead777 , great question.

Are there best practices when it comes to storing app data locally? If possible, I'd prefer to store all of it in one JSON object under a key like AppData or something and just mutate this object and store it.
Because we're talking about React Native (and the bridge between Native and JS world), it'd be best if you could split your data into smaller chunks. Each message has to be serialized into JSON before it reaches either end, so it's good practice to not clog it as much as possible.

Having a smaller pieces to work with always makes job simpler and more efficient. If your app uses only a small portion of that data in one feature and other portion in different feature, you don't want to manipulate whole data every time you do changes - just the piece that is used.

Is this an acceptable practice or should it be a series of individual key/values?

It depends of the use case. I generally try to group stored data into categories - if something is related to user, group that thing together. User has some activities? Store them as list of IDs, while activities is a separate piece of data stored.

Is there a max length allowed for the strings that can be stored under a single key?

Yes, I replied some time ago regarding a crash when someone tried to retrieve huge amount of data at once

@krizzu krizzu removed the bug Something isn't working label Mar 31, 2020
@stazrad
Copy link
Author

stazrad commented Mar 31, 2020

@krizzu now that you mention converting all app data to/from JSON on every single storage request it makes sense that it would be more performant to break it into relative chunks. Thanks for the response!

@stazrad stazrad closed this as completed Mar 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question General question about usage
Projects
None yet
Development

No branches or pull requests

2 participants