-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Wrap calls to search results and collection counts in paginate to reduce additional requests #2421
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but it'd be better if you could also get a review from someone on the themes team
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just 1 comment otherwise looks good.
{%- if search.filters != empty -%} | ||
{%- if section.settings.enable_filtering or section.settings.enable_sorting -%} | ||
<aside aria-labelledby="verticalTitle" class="facets-wrapper{% unless section.settings.enable_filtering %} facets-wrapper--no-filters{% endunless %}{% if section.settings.filter_type != 'vertical' %} page-width{% endif %}" id="main-search-filters" data-id="{{ section.id }}"> | ||
{% render 'facets', results: search, enable_filtering: section.settings.enable_filtering, enable_sorting: section.settings.enable_sorting, filter_type: section.settings.filter_type, paginate: paginate %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result.results_count
benefits from having a paginate
context within the facets
render to reduce unnecessary data retrieval. Even though the paginate
block wraps where the snippet is rendered in main-search.liquid
and main-collection-product-grid.liquid
, it is not in the context inside of the rendered liquid partial by default.
https://shopify.dev/docs/api/liquid/tags/render
Inside snippets and app blocks, you can't directly access variables that are created outside of the snippet or app block. However, you can specify variables as parameters to pass outside variables to snippets.
…uce additional requests
b973bb2
to
28394b6
Compare
* shopify/main: Gift cards/add recipient (Shopify#2412) Update 1 translation file (Shopify#2453) [Slideshow] Add ambient movement to background (Shopify#2383) Wrap calls to search results ind collection counts in paginate to reduce additional requests (Shopify#2421) [Header] Add app block in the header section (Shopify#2238) [Image with Text] Add ambient movement to image (Shopify#2385) Update 1 translation file (Shopify#2450) [Blog post section] Fix slides size on mobile (Shopify#2368) Duplicated scrollbar in drawer menu (Shopify#2400) [Header locales] Support gradients (Shopify#2386) [Image banner] Add ambient movement to background (Shopify#2342)
…uce additional requests (Shopify#2421)
PR Summary:
Performance optimization by ensuring any calls to search results and collection counts are within the proper pagination context. Also passes the paginate down to the filter render for the same reason.
Note the diff is large cause of indenting but this is a 3 line change for each file (moved the wrapping paginate block and added passing paginate to the
facets
render)suggest hiding whitespace to view changes:

Why are these changes introduced?
Improves performance of page render
What approach did you take?
Wrap any calls to
search.results
andsearch.results_count
in the paginate block inmain-search.liquid
, also passes thepaginate
to thefacets
render.Wrap any calls to
collection.results_count
,collection.products_count
andcollection.all_products_count
in the paginate block inmain-collection-product-grid.liquid
, also passes thepaginate
to thefacets
render.Visual impact on existing themes
No visual impact
Testing steps/scenarios
Ensure search & collections render the same
Checklist