Skip to content
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

[Feature] Alice didn't use database and store all data in RAM #156

Closed
EArminjon opened this issue Nov 10, 2023 · 10 comments · Fixed by #205
Closed

[Feature] Alice didn't use database and store all data in RAM #156

EArminjon opened this issue Nov 10, 2023 · 10 comments · Fixed by #205
Assignees
Labels
new issue New issue which has not been checked yet

Comments

@EArminjon
Copy link
Contributor

EArminjon commented Nov 10, 2023

Describe the bug
All requests are put in RAM instead of local database which increase and retain high memory usage for ever.
I've some download task (which contain some huge JSON ) and that stuck my app at 500mo or more in memory usage. Sometimes that lead to crash or freeze...

To Reproduce
Steps to reproduce the behavior:

  1. Do heavy JSON api call
  2. Open devtools and check memory usage

Expected behavior
Alice should load in ram only relevant data. Else, all data should be put in a local database (You can avoid SQL and use NOSQL)

Screenshots
If applicable, add screenshots to help explain your problem.

Flutter doctor
Please add flutter doctor output here.

Alice version

  • Version: 0.3.3

Smartphone (please complete the following information):

  • Device: Pixel 7 emulator
  • OS: Android 14 API 34

Additional context
Add any other context about the problem here.

@EArminjon EArminjon added the new issue New issue which has not been checked yet label Nov 10, 2023
@techouse
Copy link
Collaborator

techouse commented Jun 15, 2024

@jhomlala I have some ideas on how to make this work:

  1. ObjectBox
  2. Drift
  3. sqflite
  4. sqlbrite

I know from experience that ObjectBox is the fastest way to store and retrieve the data as a stream.

Do you have any suggestions?

CC/ @EArminjon

@EArminjon
Copy link
Contributor Author

SQL not needed i think, a classic NOSQL system is far enough ;)

ObjectBox / Hive / Isaar are good for that I believe.

Using SQL can have some side effect on Android devices because Android SQL only accept 1 READ or WRITE at a time. While iOS accept multiple.

@techouse
Copy link
Collaborator

Agreed, however, I'd stay away from Hive / Isar as they've not been updated in a while.

@techouse
Copy link
Collaborator

techouse commented Jun 15, 2024

Also, I wouldn't categorize this as a BUG per-se, but rather as a feature, since Alice should not be used in a production environment anyway due to obvious security reasons.

@EArminjon EArminjon changed the title [BUG] Alice didn't use database and store all data in RAM [Feature] Alice didn't use database and store all data in RAM Jun 15, 2024
@techouse
Copy link
Collaborator

techouse commented Jun 16, 2024

Hmm, I believe that Alice.maxCallsCount should kind of address this already

this.maxCallsCount = 1000,

@EArminjon
Copy link
Contributor Author

EArminjon commented Jun 16, 2024

Damn didn't see that !

Ty a lot.

Message to the maintainer : If you don't plan to implement DB, feel free to close this issue, this parameters is enough for dev / debug env i believe.

@techouse
Copy link
Collaborator

techouse commented Jun 22, 2024

@EArminjon implementing an optional ObjectBox data store should be doable, however, it will force the user to make additional steps like code generation, etc. Because of that, it should be made into a separate package.

@jhomlala to do this we'll probably have to change

final BehaviorSubject<List<AliceHttpCall>> callsSubject = BehaviorSubject.seeded([]);

into a Stream<List<AliceHttpCall>> so that it can then be also fed from an ObjectBox query stream, i.e.

final Box<AliceHttpCall> callsBox = store.box<AliceHttpCall>();

final Stream<List<AliceHttpCall>> callsStream = 
  callsBox
    .query()
    .order<DateTime>(AliceHttpCall_.createdTime)
    .watch(triggerImmediately: true)
    .map((Query<AliceHttpCall> query) => query.find());

and use another default List<AliceCall> variable to store the AliceHttpCalls. The ObjectBox package would then store those into a Box. Check the example here https://github.com/objectbox/objectbox-dart

I'll try and make a PR in the following days/weeks if we agree that that's the best course of action.

@jhomlala
Copy link
Owner

jhomlala commented Jun 23, 2024

That's okay but I would like to see persistence as another "plug in" package (like alice_dio etc.). This could be optional for applications which requires this storage. I don't want to force usage of ObjectBox/Hive/other db for all applications even if they don't need that.

Also we need to make sure that our DB will be cleared between sessions - we don't need to see previous sessions. Also DB
should have fixed size - we don't want to grow it too much.

@jhomlala
Copy link
Owner

Damn didn't see that !

Ty a lot.

Message to the maintainer : If you don't plan to implement DB, feel free to close this issue, this parameters is enough for dev / debug env i believe.

Well it's a valid point to use DB since there can be a lot calls with a lot of data so that's fine.

@techouse
Copy link
Collaborator

@jhomlala yea, I was planning on a "plug-in" approach, regardless, there will have to be some minor changes done to the core package to accommodate for that.

@techouse techouse linked a pull request Jun 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new issue New issue which has not been checked yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants