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

feat: 4020 - instant answers for hunger games #4099

Merged
merged 5 commits into from
Jun 8, 2023

Conversation

monsieurtanuki
Copy link
Contributor

What

  • Now, for the user, the transition between questions is instant.
  • How come?
    • now we use a new background task for hunger games - when the user enters an answer, we create a background task and immediately go to the next question
    • when we download the questions at the beginning, we also download the related products. Doing so, we don't have to download a fresh version of the next product for the next question - we already have all the needed data.

Fixes bug(s)

Files

New files:

  • background_task_hunger_games.dart: Background task about answering a hunger games question.
  • random_questions_query.dart: Robotoff questions helper, for random product questions.

Deleted file:

  • product_question_page.dart

Impacted files:

  • abstract_background_task.dart: added "hunger games"
  • background_task_crop.dart: minor refactoring
  • background_task_details.dart: minor refactoring
  • background_task_image.dart: minor refactoring
  • background_task_manager.dart: simplified the code, as we now always work on tasks with different stamps
  • background_task_refresh.dart: minor refactoring
  • background_task_unselect.dart: minor refactoring
  • new_product_page.dart: minor refactoring
  • offline_data_page.dart: minor refactoring
  • operation_type.dart: added a type for "hunger games" background task
  • product_list_import_export.dart: minor refactoring
  • product_list_page.dart: minor refactoring
  • product_questions_query.dart: pre-loads the product if relevant
  • product_questions_widget.dart: minor refactoring
  • product_refresher.dart: new standard configuration for product lists; new silent download of product lists; minor refactoring
  • question_card.dart: now downloading the product only if not in the local database
  • question_page.dart: now saving the answer with background tasks; refactored
  • questions_query.dart: refactored as abstract, with code moved to new file random_questions_query.dart
  • robotoff_insight_helper.dart: minor refactoring

New files:
* `background_task_hunger_games.dart`: Background task about answering a hunger games question.
* `random_questions_query.dart`: Robotoff questions helper, for random product questions.

Deleted file:
* `product_question_page.dart`

Impacted files:
* `abstract_background_task.dart`: added "hunger games"
* `background_task_crop.dart`: minor refactoring
* `background_task_details.dart`: minor refactoring
* `background_task_image.dart`: minor refactoring
* `background_task_manager.dart`: simplified the code, as we now always work on tasks with different stamps
* `background_task_refresh.dart`: minor refactoring
* `background_task_unselect.dart`: minor refactoring
* `new_product_page.dart`: minor refactoring
* `offline_data_page.dart`: minor refactoring
* `operation_type.dart`: added a type for "hunger games" background task
* `product_list_import_export.dart`: minor refactoring
* `product_list_page.dart`: minor refactoring
* `product_questions_query.dart`: pre-loads the product if relevant
* `product_questions_widget.dart`: minor refactoring
* `product_refresher.dart`: new standard configuration for product lists; new silent download of product lists; minor refactoring
* `question_card.dart`: now downloading the product only if not in the local database
* `question_page.dart`: now saving the answer with background tasks; refactored
* `questions_query.dart`: refactored as abstract, with code moved to new file `random_questions_query.dart`
* `robotoff_insight_helper.dart`: minor refactoring
@monsieurtanuki monsieurtanuki requested a review from a team as a code owner June 8, 2023 09:05
@github-actions github-actions bot added Product addition The easier it is to add a product and get Nutri-Score, Eco-Score, the happier the users. 🥫 Product page User lists labels Jun 8, 2023
@monsieurtanuki monsieurtanuki linked an issue Jun 8, 2023 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Jun 8, 2023

Codecov Report

Merging #4099 (9cb8d2f) into develop (bfe1d60) will decrease coverage by 0.05%.
The diff coverage is 0.00%.

@@             Coverage Diff             @@
##           develop    #4099      +/-   ##
===========================================
- Coverage    10.88%   10.84%   -0.05%     
===========================================
  Files          271      273       +2     
  Lines        13466    13517      +51     
===========================================
  Hits          1466     1466              
- Misses       12000    12051      +51     
Impacted Files Coverage Δ
...h_app/lib/background/abstract_background_task.dart 0.00% <0.00%> (ø)
...mooth_app/lib/background/background_task_crop.dart 0.00% <0.00%> (ø)
...th_app/lib/background/background_task_details.dart 0.00% <ø> (ø)
...p/lib/background/background_task_hunger_games.dart 0.00% <0.00%> (ø)
...ooth_app/lib/background/background_task_image.dart 0.00% <0.00%> (ø)
...th_app/lib/background/background_task_manager.dart 0.00% <ø> (ø)
.../lib/background/background_task_refresh_later.dart 0.00% <0.00%> (ø)
...h_app/lib/background/background_task_unselect.dart 0.00% <0.00%> (ø)
...ges/smooth_app/lib/data_models/operation_type.dart 0.00% <0.00%> (ø)
...kages/smooth_app/lib/helpers/analytics_helper.dart 0.00% <0.00%> (ø)
... and 14 more

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

Copy link
Collaborator

@g123k g123k left a comment

Choose a reason for hiding this comment

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

Just a few feedbacks, but in general LGTM

@@ -198,7 +198,7 @@ class BackgroundTaskCrop extends BackgroundTaskUpload {
final LocalDatabase localDatabase,
final bool success,
) async {
localDatabase.upToDate.terminate(uniqueId);
await super.postExecute(localDatabase, success);
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you say await here, wouldn't be better to also have an async call for the delete just below?
(Just a suggestion)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you say await here, wouldn't be better to also have an async call for the delete just below? (Just a suggestion)

That would probably work the same, wouldn't it? Especially here, where we delete just one file in a background task.

return result;
}
} catch (e) {
//
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there's something missing here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there's something missing here :)

Actually, nothing's missing here. We just try to fromJson a map, and very often it's going to fail because some expected fields won't be there - if it is a background task from a different class. All other background tasks work on the same principle. cf. AbstractBackgroundTask.fromJson.
That said, I agree that it's not very elegant.
Feel free to create an issue to refactor that fromJson.

insightAnnotation.value,
uniqueId,
);
await task.addToManager(localDatabase, widget: widget);
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not return here, instead of the await?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why not return here, instead of the await?

As far as I know that would be exactly the same, wouldn't it?

Future<void> upload() async {
final InsightAnnotation? annotation =
_getInsightAnnotation(insightAnnotation);
if (annotation == null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't be a good idea to log this kind of error to measure the volume of potentials errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's very very unlikely to happen, as we previously populated the task field as InsightAnnotation.
Feel free to create an issue if really needed.

@monsieurtanuki
Copy link
Contributor Author

Thank you @g123k for your review!

Feel free to approve this PR if my answers made sense to you.

Copy link
Member

@teolemon teolemon left a comment

Choose a reason for hiding this comment

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

After a quick discussion with @g123k, let's merge as it

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

Successfully merging this pull request may close these issues.

Error in trunk Don't block the screen while saving a Hunger Games answer
4 participants