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

Wrap calls to search results and collection counts in paginate to reduce additional requests #2421

Merged
merged 1 commit into from
Mar 20, 2023

Conversation

zacharyreynochiasson
Copy link
Contributor

@zacharyreynochiasson zacharyreynochiasson commented Mar 17, 2023

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:
Screenshot 2023-03-18 at 12 19 57 AM

Why are these changes introduced?

Improves performance of page render

What approach did you take?

  • Wrap any calls to search.results and search.results_count in the paginate block in main-search.liquid, also passes the paginate to the facets render.

  • Wrap any calls to collection.results_count, collection.products_count and collection.all_products_count in the paginate block in main-collection-product-grid.liquid, also passes the paginate to the facets render.

Visual impact on existing themes

No visual impact

Testing steps/scenarios

Ensure search & collections render the same

Checklist

FCalabria
FCalabria previously approved these changes Mar 17, 2023
Copy link
Contributor

@FCalabria FCalabria left a 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

@ludoboludo ludoboludo requested review from ludoboludo and removed request for tyleralsbury March 17, 2023 18:20
Copy link
Contributor

@ludoboludo ludoboludo left a 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 %}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it needed here to pass in the paginate object here 🤔 I don't see it referenced in the snippet.
If we an attribute to the render we want to add it to the snippet itself in the description at the top of the file:

Screenshot

Copy link
Contributor Author

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.

@zacharyreynochiasson zacharyreynochiasson changed the title Wrap calls to search results in paginate to reduce additional requests Wrap calls to search results and collection counts in paginate to reduce additional requests Mar 18, 2023
@ludoboludo ludoboludo self-assigned this Mar 20, 2023
@ludoboludo ludoboludo merged commit 30d3253 into main Mar 20, 2023
@ludoboludo ludoboludo deleted the optimize_search_paginate branch March 20, 2023 16:24
pangloss added a commit to pangloss/dawn that referenced this pull request Mar 23, 2023
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants