Skip to content

Commit

Permalink
fix: remove non-JS list of products (#10743)
Browse files Browse the repository at this point in the history
As discussed on the product opener meeting on Monday, this removes the
HTML list of products that that is displayed when browsers have turned
off Javascript. This is done for performance reasons, to avoid having
browsers download the data twice. It also makes the responses smaller
and easier to cache.
  • Loading branch information
stephanegigandet authored Aug 28, 2024
1 parent e1a485e commit 6805b9f
Show file tree
Hide file tree
Showing 39 changed files with 21,859 additions and 864 deletions.
4 changes: 3 additions & 1 deletion lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ my $uri_finder = URI::Find->new(
# Sort keys of JSON output
# $json has utf8 disabled: it encodes to Perl Unicode strings
my $json = JSON::MaybeXS->new->utf8(0)->allow_nonref->canonical;
my $json_indent = JSON::MaybeXS->new->indent(1)->utf8(0)->allow_nonref->canonical;
# $json_utf8 has utf8 enabled: it encodes to UTF-8 bytes
my $json_utf8 = JSON::MaybeXS->new->utf8(1)->allow_nonref->canonical;

Expand Down Expand Up @@ -5645,7 +5646,8 @@ sub search_and_display_products ($request_ref, $query_ref, $sort_by, $limit, $pa
my $products_json = '[]';

if (defined $request_ref->{structured_response}{products}) {
$products_json = $json->encode($request_ref->{structured_response}{products});
# We indent the JSON in the generated HTML so that we can easily see diffs in integration tests outputs
$products_json = $json_indent->encode($request_ref->{structured_response}{products});
}

my $contributor_prefs_json = $json->encode(
Expand Down
15 changes: 2 additions & 13 deletions templates/web/common/includes/list_of_products.tt.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,9 @@
[% product.product_name %]
</a>
</li>
[% ELSE %]
<li>
[% IF product.product_name == '' %]
<a href="[% product.url %]" title="[% product.code %]">
[% ELSE %]
<a href="[% product.url %]" title="[% product.product_name %]">
[% END %]
<div>[% product.img %]</div>
<span>[% product.product_name %]</span>
</a>
</li>
[% END %]
[% END %]
[% IF (jqm.defined) && !(jqm_loadmore.defined) %]
[% END %]
[% IF (jqm.defined) && !(jqm_loadmore.defined) %]
</ul>
[% ELSE %]
</ul>
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,8 @@ <h3 class="title-5 text-medium">Descubre el proyecto</h3>
var page_type = "products";
var preferences_text = "Clasifica los productos 0 de acuerdo a tus preferencias";
var contributor_prefs = {"display_barcode":null,"edit_link":null};
var products = [];
var products = []
;
</script>
<script src="//static.openfoodfacts.localhost/js/product-preferences.js"></script>
<script src="//static.openfoodfacts.localhost/js/product-search.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,8 @@ <h3 class="title-5 text-medium">Discover the project</h3>
var page_type = "products";
var preferences_text = "Classify the 0 products below according to your preferences";
var contributor_prefs = {"display_barcode":null,"edit_link":null};
var products = [];
var products = []
;
</script>
<script src="//static.openfoodfacts.localhost/js/product-preferences.js"></script>
<script src="//static.openfoodfacts.localhost/js/product-search.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ <h3 class="title-5 text-medium">Discover the project</h3>
var page_type = "products";
var preferences_text = "Classify the 0 products below according to your preferences";
var contributor_prefs = {"display_barcode":null,"edit_link":null};
var products = [];
var products = []
;
</script>
<script src="//static.openfoodfacts.localhost/js/product-preferences.js"></script>
<script src="//static.openfoodfacts.localhost/js/product-search.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ <h3 class="title-5 text-medium">Discover the project</h3>
var page_type = "products";
var preferences_text = "Classify the 0 products below according to your preferences";
var contributor_prefs = {"display_barcode":null,"edit_link":null};
var products = [];
var products = []
;
</script>
<script src="//static.openfoodfacts.localhost/js/product-preferences.js"></script>
<script src="//static.openfoodfacts.localhost/js/product-search.js"></script>
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ <h3 class="title-5 text-medium">Discover the project</h3>
var page_type = "products";
var preferences_text = "Classify the 0 products below according to your preferences";
var contributor_prefs = {"display_barcode":null,"edit_link":null};
var products = [];
var products = []
;
</script>
<script src="//static.openfoodfacts.localhost/js/product-preferences.js"></script>
<script src="//static.openfoodfacts.localhost/js/product-search.js"></script>
Expand Down

Large diffs are not rendered by default.

1,031 changes: 994 additions & 37 deletions tests/integration/expected_test_results/web_html/fr-categories.html

Large diffs are not rendered by default.

2,398 changes: 2,313 additions & 85 deletions tests/integration/expected_test_results/web_html/fr-index.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

689 changes: 664 additions & 25 deletions tests/integration/expected_test_results/web_html/fr-search-results.html

Large diffs are not rendered by default.

2,057 changes: 1,984 additions & 73 deletions tests/integration/expected_test_results/web_html/world-categories.html

Large diffs are not rendered by default.

4,450 changes: 4,293 additions & 157 deletions tests/integration/expected_test_results/web_html/world-index-signedin.html

Large diffs are not rendered by default.

4,450 changes: 4,293 additions & 157 deletions tests/integration/expected_test_results/web_html/world-index.html

Large diffs are not rendered by default.

1,715 changes: 1,654 additions & 61 deletions tests/integration/expected_test_results/web_html/world-label-organic.html

Large diffs are not rendered by default.

1,715 changes: 1,654 additions & 61 deletions tests/integration/expected_test_results/web_html/world-search-results.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"original_query_string" : "api/v0/attribute_groups",
"page" : 1,
"query_string" : "api/v0/attribute_groups",
"rate_limiter_bucket" : null,
"rate_limiter_blocking" : 0,
"rate_limiter_bucket" : null,
"rate_limiter_limit" : null,
"rate_limiter_user_requests" : null
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"original_query_string" : "api/v3/product/03564703999971",
"page" : 1,
"query_string" : "api/v3/product/03564703999971",
"rate_limiter_bucket" : "product",
"rate_limiter_blocking" : 0,
"rate_limiter_bucket" : "product",
"rate_limiter_limit" : 100,
"rate_limiter_user_requests" : null
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"original_query_string" : "api/v3/product/https%3A%2F%2Fid.gs1.org%2F01%2F03564703999971%2F10%2FABC%2F21%2F123456%3F17%3D211200",
"page" : 1,
"query_string" : "api/v3/product/https%3A%2F%2Fid.gs1.org%2F01%2F03564703999971%2F10%2FABC%2F21%2F123456%3F17%3D211200",
"rate_limiter_bucket" : "product",
"rate_limiter_blocking" : 0,
"rate_limiter_bucket" : "product",
"rate_limiter_limit" : 100,
"rate_limiter_user_requests" : null
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"page" : 1,
"param" : {},
"query_string" : "category/breads/ingredients",
"rate_limiter_blocking" : 0,
"rate_limiter_bucket" : "facet_tags",
"rate_limiter_limit" : null,
"rate_limiter_user_requests" : null,
"tag" : "es:breads",
"tag_prefix" : "",
"tagid" : "es:breads",
Expand All @@ -22,9 +26,5 @@
"tagtype" : "categories"
}
],
"tagtype" : "categories",
"rate_limiter_bucket": "facet_tags",
"rate_limiter_blocking" : 0,
"rate_limiter_limit" : null,
"rate_limiter_user_requests" : null
"tagtype" : "categories"
}
10 changes: 5 additions & 5 deletions tests/unit/expected_test_results/routing/facet-url-group-by.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"page" : 1,
"param" : {},
"query_string" : "category/breads/ingredients",
"rate_limiter_blocking" : 0,
"rate_limiter_bucket" : "facet_tags",
"rate_limiter_limit" : null,
"rate_limiter_user_requests" : null,
"tag" : "en:breads",
"tag_prefix" : "",
"tagid" : "en:breads",
Expand All @@ -22,9 +26,5 @@
"tagtype" : "categories"
}
],
"tagtype" : "categories",
"rate_limiter_bucket": "facet_tags",
"rate_limiter_blocking" : 0,
"rate_limiter_limit" : null,
"rate_limiter_user_requests" : null
"tagtype" : "categories"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
"page" : "4",
"param" : {},
"query_string" : "category/breads/4",
"rate_limiter_blocking" : 0,
"rate_limiter_bucket" : "facet_products",
"rate_limiter_limit" : null,
"rate_limiter_user_requests" : null,
"tag" : "en:breads",
"tag_prefix" : "",
"tagid" : "en:breads",
Expand All @@ -21,9 +25,5 @@
"tagtype" : "categories"
}
],
"tagtype" : "categories",
"rate_limiter_bucket" : "facet_products",
"rate_limiter_blocking" : 0,
"rate_limiter_limit" : null,
"rate_limiter_user_requests" : null
"tagtype" : "categories"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"page" : "4",
"param" : {},
"query_string" : "category/bread/4",
"rate_limiter_bucket" : "facet_products",
"rate_limiter_blocking" : 0,
"rate_limiter_bucket" : "facet_products",
"rate_limiter_limit" : 5,
"rate_limiter_user_requests" : null,
"tag" : "en:bread",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/expected_test_results/routing/facet-url.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"page" : 1,
"param" : {},
"query_string" : "category/breads",
"rate_limiter_bucket" : "facet_products",
"rate_limiter_blocking" : 0,
"rate_limiter_bucket" : "facet_products",
"rate_limiter_limit" : 10,
"rate_limiter_user_requests" : null,
"tag" : "en:breads",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"original_query_string" : "api/v3/geopip/12.45.23.45",
"page" : 1,
"query_string" : "api/v3/geopip/12.45.23.45",
"rate_limiter_bucket" : null,
"rate_limiter_blocking" : 0,
"rate_limiter_bucket" : null,
"rate_limiter_limit" : null,
"rate_limiter_user_requests" : null
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"original_query_string" : "api/v3/geopip/2001:ac8:25:3b::e01d",
"page" : 1,
"query_string" : "api/v3/geopip/2001:ac8:25:3b::e01d",
"rate_limiter_bucket" : null,
"rate_limiter_blocking" : 0,
"rate_limiter_bucket" : null,
"rate_limiter_limit" : null,
"rate_limiter_user_requests" : null
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"page" : 1,
"param" : {},
"query_string" : "category/breads/no-nutrition-data",
"rate_limiter_bucket" : null,
"rate_limiter_blocking" : 0,
"rate_limiter_bucket" : null,
"rate_limiter_limit" : null,
"rate_limiter_user_requests" : null,
"status_code" : 404,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"original_query_string" : "products/3564703999971",
"page" : 1,
"query_string" : "products/3564703999971",
"rate_limiter_bucket" : null,
"rate_limiter_blocking" : 0,
"rate_limiter_bucket" : null,
"rate_limiter_limit" : null,
"rate_limiter_user_requests" : null,
"search" : 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"original_query_string" : "products/3564703999971,3564703999972",
"page" : 1,
"query_string" : "products/3564703999971,3564703999972",
"rate_limiter_bucket" : null,
"rate_limiter_blocking" : 0,
"rate_limiter_bucket" : null,
"rate_limiter_limit" : null,
"rate_limiter_user_requests" : null,
"search" : 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
"page" : 1,
"param" : {},
"query_string" : "category/breads",
"rate_limiter_bucket" : "facet_products",
"rate_limiter_blocking" : 0,
"rate_limiter_bucket" : "facet_products",
"rate_limiter_limit" : 10,
"rate_limiter_user_requests" : null,
"tag" : "en:breads",
"tag_prefix" : "",
"tagid" : "en:breads",
"user_id": "userid",
"tags" : [
{
"tag" : "en:breads",
Expand All @@ -26,5 +25,6 @@
"tagtype" : "categories"
}
],
"tagtype" : "categories"
"tagtype" : "categories",
"user_id" : "userid"
}

0 comments on commit 6805b9f

Please sign in to comment.