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: refactor to allow unlimited facets - WIP #9332

Merged
merged 13 commits into from
Nov 20, 2023
Merged

Conversation

stephanegigandet
Copy link
Contributor

@stephanegigandet stephanegigandet commented Nov 16, 2023

Some initial refactoring to allow to have an unlimited number of / in URLs.

image

@codecov-commenter
Copy link

codecov-commenter commented Nov 16, 2023

Codecov Report

Attention: 252 lines in your changes are missing coverage. Please review.

Comparison is base (80bcc29) 48.05% compared to head (1c449c9) 48.61%.
Report is 8 commits behind head on main.

Files Patch % Lines
lib/ProductOpener/Display.pm 20.68% 216 Missing and 14 partials ⚠️
lib/ProductOpener/Routing.pm 56.52% 10 Missing and 10 partials ⚠️
lib/ProductOpener/Tags.pm 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9332      +/-   ##
==========================================
+ Coverage   48.05%   48.61%   +0.56%     
==========================================
  Files          65       65              
  Lines       20301    20256      -45     
  Branches     4921     4894      -27     
==========================================
+ Hits         9756     9848      +92     
+ Misses       9295     9151     -144     
- Partials     1250     1257       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@alexgarel alexgarel left a comment

Choose a reason for hiding this comment

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

Great move !

I propose a small refactoring to have even better readability.

lib/ProductOpener/Display.pm Show resolved Hide resolved
}
my $tagid = $tag_ref->{tagid};
my $tagtype = $tag_ref->{tagtype};
my $tag_prefix = $tag_ref->{tag_prefix};
Copy link
Member

Choose a reason for hiding this comment

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

can you add a comment on what is tag_prefix ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

lib/ProductOpener/Display.pm Show resolved Hide resolved
my $tag_prefix = $tag_ref->{tag_prefix};
my $display_tag;
my $canon_tagid;
my $newtagid;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
my $newtagid;
# tag name in $lc corresponding to $canon_tagid
# (if it's not the same as $tagid, we will redirect the request)
my $newtagid;

@@ -408,152 +408,116 @@ sub analyze_request ($request_ref) {
if $log->is_debug();
}

if (
# Extract tag type / tag value pairs and store them in an array $request_ref->{tags}
Copy link
Member

Choose a reason for hiding this comment

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

Could we extract this part in a separate sub (making code easier to read) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.


=cut

sub sort_products_for_test_comparison ($array_ref, $sort_field) {
Copy link
Member

Choose a reason for hiding this comment

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

Good idea to make it a sub even if it's a one-liner, it really helps understand the code more easily.

# to see data quality panels
execute_api_tests(__FILE__, $tests_ref, $ua);

done_testing();
Copy link
Member

Choose a reason for hiding this comment

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

😍 some more integration tests

@github-actions github-actions bot added Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. Tags labels Nov 17, 2023
@stephanegigandet
Copy link
Contributor Author

Sample mongodb query for http://world.openfoodfacts.localhost/label/organic/category/unknown/labels :

{query => [{'$match' => {categories_tags => {'$in' => [undef,[]]},labels_tags => 'en:organic'}},{'$unwind' => '$labels_tags'},{'$group' => {_id => '$labels_tags',count => {'$sum' => 1}}},{'$sort' => {count => -1}},{'$skip' => 0},{'$limit' => 10000}]

Copy link

sonarcloud bot commented Nov 20, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@stephanegigandet stephanegigandet merged commit 77cf12e into main Nov 20, 2023
13 checks passed
@stephanegigandet stephanegigandet deleted the unlimited-facets branch November 20, 2023 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Display Tags Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. 🧪 tests 🧪 unit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants