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

Add metadata about local Product, for better refresh flexibility #4947

Closed
monsieurtanuki opened this issue Jan 3, 2024 · 7 comments · Fixed by #5016
Closed

Add metadata about local Product, for better refresh flexibility #4947

monsieurtanuki opened this issue Jan 3, 2024 · 7 comments · Fixed by #5016

Comments

@monsieurtanuki
Copy link
Contributor

Problem

We store products locally with only one metadata: the timestamp of the latest insertion/update in the local database (last_update).
If we want to do smart database refreshes (e.g. new language), that may not be enough.
"Smart" refreshes mean something more refined than "refresh all the products in one shot".

Proposed solution

The first example that comes to mind is the language. When we download a product, we call the API with a language parameter.
We could store locally the queried language as a metadata, at the same time as we store the product.
With that metadata, we could run queries like "give the local products in history that are not in Italian (new language), most recent first"

Of course, other metadata could be added.
Possibly, additional OFF metadata extracted from the product (like the OFF "last update"). For queries like "give me the local products whose server refresh is more than 2 months old".
Not sure if the country would be as relevant as the language.

Part of

@monsieurtanuki monsieurtanuki self-assigned this Jan 3, 2024
@monsieurtanuki
Copy link
Contributor Author

My first tests are very interesting.
It looks like we'd be able to just frequently say "btw just refresh the most recent products that are not in the current language, and keep doing so".

@monsieurtanuki
Copy link
Contributor Author

Possible improvement: a "last access" metadata, cf. @LuanRoger in #4717 (comment).
To be considered carefully: that would mean "writing" each time we "read" a product, and for the moment we write only when we download a product.

@monsieurtanuki
Copy link
Contributor Author

Now that #4951 is merged, we have all we need to automatically refresh the products when the app language changes.
Smoothly.
The first step will be: "refresh 10 products that are not in the right language, and do it again".
Then some fine tunings, about which products are more interesting and should be refreshed first.

@monsieurtanuki
Copy link
Contributor Author

@teolemon I'm sure you'll love that. I don't know if I'll be able to PR today but by the time I switched from the preferences (language: French -> Italian) to the history list, the products were translated!

French Italian
Screenshot_1704726907 Screenshot_1704727040

@monsieurtanuki
Copy link
Contributor Author

I've just lost all today's code because of merge conflicts with the important matter of #4938's test tube being empty or filled...

@monsieurtanuki
Copy link
Contributor Author

With #4951 and #4969 now merged, we have 2 new metadata:

  • the language of the server query when the product was downloaded
  • the timestamp of the latest local access to the product (e.g. open product page or open product list page)

With those metadata it's very easy to solve the "app language change" problem:

  • are there products that were not downloaded in the same language as the app?
  • if so, let's download the products in the new language, for the most interesting products first (e.g. ordered by descending timestamp)

For the nutriscore refresh, the problem is a bit different:

  • how do we know the nutriscore hasn't been potentially refreshed yet, in general or for a product? Like, if the product server last_update timestamp is prior a date, like April 1st 2024?
  • how could we track which products we still have to refresh? A trick would be to empty the download-language metadata, which would trigger the database refresh on grounds of empty=wrong language.

@monsieurtanuki
Copy link
Contributor Author

This week-end I'll PR the automatic translation system at each app language change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants