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

fix: 4066 - top n product download split in smaller robust parts #4166

Merged
merged 8 commits into from
Jun 21, 2023

Conversation

monsieurtanuki
Copy link
Contributor

@monsieurtanuki monsieurtanuki commented Jun 15, 2023

What

Currently working on the top n offline downloads.

The main idea is to

  • separate the whole process in 2 parts - listing the barcodes, then downloading the related products
  • split each sub-process in smaller parts, "paging"

Doing so we have less potential performance and connection problems, and we don't block the other user actions.

The only thing that is missing now is having a background task calling the next background task (e.g. the next download "page") with immediate execution. That's the first time we would need that in the app - so far we have the "upload image" + "refresh the product 10 minutes later", which is not immediate.

The same split (get barcodes then download products) would be applied to the local database refresh from the server.

Screenshot

Fixes bug(s)

Files

New files:

  • background_offline_barcodes.dart: Background subtask about pre-downloading top n barcodes.
  • background_offline_products.dart: Background subtask about downloading products.
  • dao_work_barcode.dart: Work table that contains barcodes.

Impacted files:

  • background_task_offline.dart: now we clean the new DaoWorkBarcode and we just call the new BackgroundtaskOfflineBarcodes
  • local_database.dart: upgraded to version 3, with the new DaoWorkBarcode.
  • operation_type.dart: added the new 2 background tasks.

New files:
* `background_offline_barcodes.dart`: Background subtask about pre-downloading top n barcodes.
* `background_offline_products.dart`: Background subtask about downloading products.
* `dao_work_barcode.dart`: Work table that contains barcodes.

Impacted files:
* `background_task_offline.dart`: now we clean the new `DaoWorkBarcode` and we just call the new `BackgroundtaskOfflineBarcodes`
* `local_database.dart`: upgraded to version 3, with the new `DaoWorkBarcode`.
* `operation_type.dart: added the new 2 background tasks.

TODO
* `backgrount_task_manager.dart`: make it possible to actually chain tasks with immediate execution
@teolemon
Copy link
Member

@monsieurtanuki Could you clarify what's left to move from draft to reviewable ?

@monsieurtanuki
Copy link
Contributor Author

@monsieurtanuki Could you clarify what's left to move from draft to reviewable ?

In terms of code and files, no.
In terms of features, I wrote it in the OP: "The only thing that is missing now is..."

It looks like I needed that "push as draft" step in order to focus on a specific feature and a different file.

I'll push the rest by the end of the week.

@monsieurtanuki
Copy link
Contributor Author

I'll undraft it tomorrow.
@teolemon @stephanegigandet I've managed to download the top 10k products of FR_fr (4 minutes to download the barcodes, then 14 minutes to download the products). As background tasks, so no interference with the user.
2 products are missing: could be that the loop on all pages in the top N barcodes works only at 99.98%.

top n barcode download related product download et voilà: 9998 products
Screenshot_2023-06-17-19-08-02 Screenshot_2023-06-17-19-11-54 Screenshot_2023-06-17-19-25-55

Looking for a product when offline (immediate result):

top of product page bottom of product page
Screenshot_2023-06-17-19-34-45 Screenshot_2023-06-17-19-34-51

New files:
* `background_task_paged.dart`: Abstract background task with paged actions.
* `background_task_progressing.dart`: Abstract background task with work in progress actions.

Impacted files:
* `background_task_crop.dart`: minor refactoring
* `background_task_details.dart`: minor refactoring
* `background_task_hunger_games.dart`: minor refactoring
* `background_task_image.dart`: minor refactoring
* `background_task_refresh_later.dart`: minor refactoring
* `background_task_unselect.dart`: minor refactoring
* `background_task_upload.dart`: minor refactoring
* `dao_work_barcode.dart`: minor refactoring
* `edit_product_page.dart`: minor refactoring
* `local_database.dart`: minor refactoring
* `new_product_page.dart`: minor refactoring
* `offline_tasks_page.dart`: minor refactoring; displays progress percentage
* `operation_type.dart`: moved file; minor refactoring for progress percentage
* `product_image_gallery_view.dart`: minor refactoring
* `up_to_date_changes.dart`: minor refactoring

Later:
* `background_task.dart`
* `background_task_download_products.dart`
* `background_task_full_refresh.dart`
* `background_task_manager.dart`
* `background_task_offline.dart`
* `background_task_top_barcodes.dart`
* `offline_data_page.dart`
@github-actions github-actions bot added background tasks Product addition The easier it is to add a product and get Nutri-Score, Eco-Score, the happier the users. 🥫 Product page labels Jun 17, 2023
Impacted files:
* `app_en.arb`: added a label for topN download with parameter
* `background_task.dart`: added a bool getter for immediate exec of the next task; minor refactoring
* `background_task_download_products.dart`: now as a _progressing_ background task, reused for top N, with KP and without KP
* `background_task_full_refresh.dart`: now as a _paged_ background task, that opens two progressing download tasks (one with KP, one without KP)
* `background_task_manager.dart`: now working as singleton; added a special case for immediate exec of the next task
* `background_task_offline.dart`: now as a _progressing_ background task
* `background_task_top_barcodes.dart`: now as a _progressing_ background task
* `dao_work_barcodes.dart`: fixed the bulk insert and delete for more than 1K products (actually, 1K SQL parameters)
* `offline_data_page.dart`: now using topN and pageSize parameters
* `offline_tasks_page.dart`: added a "work" label for the tasks
* `operation_type.dart`: now embeds the "work" in the task id
@codecov-commenter
Copy link

codecov-commenter commented Jun 18, 2023

Codecov Report

Merging #4166 (c736cc8) into develop (03d2dcb) will increase coverage by 0.12%.
The diff coverage is 0.00%.

@@             Coverage Diff             @@
##           develop    #4166      +/-   ##
===========================================
+ Coverage    10.88%   11.00%   +0.12%     
===========================================
  Files          276      282       +6     
  Lines        13581    14015     +434     
===========================================
+ Hits          1478     1543      +65     
- Misses       12103    12472     +369     
Impacted Files Coverage Δ
...ges/smooth_app/lib/background/background_task.dart 0.00% <0.00%> (ø)
...mooth_app/lib/background/background_task_crop.dart 0.00% <ø> (ø)
...th_app/lib/background/background_task_details.dart 0.00% <0.00%> (ø)
.../background/background_task_download_products.dart 0.00% <0.00%> (ø)
...p/lib/background/background_task_full_refresh.dart 0.00% <0.00%> (ø)
...p/lib/background/background_task_hunger_games.dart 0.00% <ø> (ø)
...ooth_app/lib/background/background_task_image.dart 0.00% <ø> (ø)
...th_app/lib/background/background_task_manager.dart 0.00% <0.00%> (ø)
...th_app/lib/background/background_task_offline.dart 0.00% <0.00%> (ø)
...ooth_app/lib/background/background_task_paged.dart 0.00% <0.00%> (ø)
... and 14 more

... and 39 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@monsieurtanuki monsieurtanuki marked this pull request as ready for review June 18, 2023 14:47
@monsieurtanuki monsieurtanuki requested a review from a team as a code owner June 18, 2023 14:47
@monsieurtanuki monsieurtanuki requested a review from teolemon June 18, 2023 14:47
@monsieurtanuki
Copy link
Contributor Author

Final touch is the refresh local database part:

  • starts with the list of all local products split in 2 - with or without KP
  • and then we create two tasks - one for the download with KP, the other without KP
refresh task downloading w/ w/out KP downloading only w/out KP
Screenshot_2023-06-18-16-20-44 Screenshot_2023-06-18-16-20-59 Screenshot_2023-06-18-16-21-23

monsieurtanuki and others added 4 commits June 18, 2023 19:30
…oducts.dart

Co-authored-by: Pierre Slamich <pierre.slamich@gmail.com>
…oducts.dart

Co-authored-by: Pierre Slamich <pierre.slamich@gmail.com>
….dart

Co-authored-by: Pierre Slamich <pierre.slamich@gmail.com>
….dart

Co-authored-by: Pierre Slamich <pierre.slamich@gmail.com>
Copy link
Member

@M123-dev M123-dev left a comment

Choose a reason for hiding this comment

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

Heyyy @monsieurtanuki looks good to me. You are the one with the background task understanding. Just a few general comments

pageSize,
);
if (barcodes.isEmpty) {
// we're done!
Copy link
Member

Choose a reason for hiding this comment

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

Yayy

);
await task.addToManager(localDatabase, widget: widget);
}

@override
String? getSnackBarMessage(final AppLocalizations appLocalizations) =>
'Starting the download of the most popular products'; // TODO(monsieurtanuki): localize
'Starting the download of the most popular products';
Copy link
Member

Choose a reason for hiding this comment

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

Why did you remove the todo

@monsieurtanuki
Copy link
Contributor Author

Thank you @M123-dev for your review!

I added localizations, after your comment.
It's a bit problematic that I am the only one working on background tasks, but at least each time I try to refactor them so that they are lighter to read - and potentially easier to understand.

@monsieurtanuki monsieurtanuki merged commit 95c3a67 into openfoodfacts:develop Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
background tasks database 🌐 l10n Offline - Browsing Product addition The easier it is to add a product and get Nutri-Score, Eco-Score, the happier the users. 🥫 Product page
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace the current server call for offline products to something more scalable
4 participants