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

Reload the product on upload/edit task success #2968

Closed
teolemon opened this issue Sep 7, 2022 · 9 comments
Closed

Reload the product on upload/edit task success #2968

teolemon opened this issue Sep 7, 2022 · 9 comments
Assignees
Labels
🐛 bug Something isn't working data refresh 🎯 P1
Milestone

Comments

@teolemon
Copy link
Member

teolemon commented Sep 7, 2022

Why

  • I added a category from a sub-knowledge panel, it queued the edit and piped it through offline edit
  • I had to reload manually

What

  • Reload the product on upload/edit task success
@monsieurtanuki
Copy link
Contributor

@teolemon The result should be instant, regardless of the task being executed (if I understood correctly the offline mode).
That's why we need to refactor the "offline edit/task queue/local refresh/server refresh" process, so that ANY edit will follow the same process.

@monsieurtanuki
Copy link
Contributor

@AshAman999 If that's OK with you, I'll do the refactoring first.

@AshAman999
Copy link
Member

@AshAman999 If that's OK with you, I'll do the refactoring first.

@monsieurtanuki
Yeah sure no problem in that, i can look for it once ur refactoring is done ☑️

@monsieurtanuki
Copy link
Contributor

@AshAman999 Now that I've refactored and understood better the background tasks, I think that in order to fix the current issue we should not only update the LocalDatabase, but also the UpToDateProductProvider. How can we do that with a call to callbackDispatcher?

@AshAman999
Copy link
Member

Hello @monsieurtanuki
The current place from main.dart seems like the only place where it seems to work perfectly,
If we could move that code somewhere else then it would work the way u suggesting it would be easy to just pass the provider, but it doesn't work if I call callbackDispatcherfrom somewhere else;

Another workaround could be using Consumer2<UpToDateProductProvider,localdatabase> instead of Consumer<UpToDateProductProvider> where we are building widgets so that it could listen to changes on both the providers, and when it rebuilds we call the database to put the product in the DB to the views/provider.
Even better would be to use selectors, so that we could listen to precisely the changes so only in certain cases we rebuild the widgets. As Edouard suggested this idea of using selectors

I am trying on to fix these soon, but just running into a clash with my university exams, will try to find a remedy soon

@monsieurtanuki
Copy link
Contributor

Hi @AshAman999!
Not convinced in a first approach by neither Consumer2 nor selectors.
I think we would be better off if we merged UpToDateProductProvider's features into LocalDatabase: it would be accessible from anywhere, even from callbackDispatcher. And functionally that would be relevant: an advanced product cache in the local database, in addition to sqflite.

@monsieurtanuki
Copy link
Contributor

Working on it...

@monsieurtanuki
Copy link
Contributor

I think I've figured it out.

The problem we're trying to solve here is: "on all pages that display data about a product, we want a refresh with the latest locally updated data".

How do data get updated locally?

  • either directly by the end user when she changes for instance a category
    • we immediately change the data locally
    • we upload the changes in a background process, then download the whole product and store it locally
  • or when the user performs a search: the data is downloaded and stored locally

How can we get an immediate refresh:

  • we need instant access to the fresh data - sqflite is not an option, being async - we can store data in Maps in a slngleton
  • we need to notify the impacted pages / widgets

The instant access has a cost, as we cannot store in Maps all the products "just in case". But:

  • we can limit that instant cache to products edited by the user - that's more or less already implemented
  • we can limit that instant cache to products currently viewed by the user, by incrementing/decrementing a counter related to the barcode - basically we don't care about other products, regarding freshness

With that in mind, we can move UpToDateProductProvider to LocalDatabase or DaoProduct.

About to implement and test...

@monsieurtanuki
Copy link
Contributor

Probably fixed by #3018, with pending #3263.
Feel free to reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working data refresh 🎯 P1
Development

No branches or pull requests

4 participants