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. Collection - add pagination to limit the amount of fetched data #3688

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 28 additions & 23 deletions sections/featured-collection.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,33 @@
aria-label="{{ 'general.slider.name' | t }}"
>
{% assign skip_card_product_styles = false %}
{%- for product in section.settings.collection.products limit: section.settings.products_to_show -%}
<li
id="Slide-{{ section.id }}-{{ forloop.index }}"
class="grid__item{% if show_mobile_slider or show_desktop_slider %} slider__slide{% endif %}{% if settings.animations_reveal_on_scroll %} scroll-trigger animate--slide-in{% endif %}"
{% if settings.animations_reveal_on_scroll %}
data-cascade
style="--animation-order: {{ forloop.index }};"
{% endif %}
>
{% render 'card-product',
card_product: product,
media_aspect_ratio: section.settings.image_ratio,
image_shape: section.settings.image_shape,
show_secondary_image: section.settings.show_secondary_image,
show_vendor: section.settings.show_vendor,
show_rating: section.settings.show_rating,
skip_styles: skip_card_product_styles,
section_id: section.id,
quick_add: section.settings.quick_add
%}
</li>
{%- assign skip_card_product_styles = true -%}

{%- if section.settings.collection.products.size > 0 -%}
{% paginate section.settings.collection.products by section.settings.products_to_show %}
{%- for product in section.settings.collection.products limit: section.settings.products_to_show -%}
Copy link
Contributor

Choose a reason for hiding this comment

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

I might be confused, but isn't using the paginate tag already giving us the "limit"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point 🤔 In this context it doesn't seem like the limit would be needed if the pagination alone is already limiting the amount of data fetched.
cc: @krzksz

Copy link
Contributor

@Roi-Arthur Roi-Arthur Jan 7, 2025

Choose a reason for hiding this comment

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

It might be a happy accident / unintended result of how these tags work and not best practice; either way just trying to understand these 2 tags better 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated 👍 Removed the limit from the for loop since like mentioned it's already being paginated.

<li
id="Slide-{{ section.id }}-{{ forloop.index }}"
class="grid__item{% if show_mobile_slider or show_desktop_slider %} slider__slide{% endif %}{% if settings.animations_reveal_on_scroll %} scroll-trigger animate--slide-in{% endif %}"
{% if settings.animations_reveal_on_scroll %}
data-cascade
style="--animation-order: {{ forloop.index }};"
{% endif %}
>
{% render 'card-product',
card_product: product,
media_aspect_ratio: section.settings.image_ratio,
image_shape: section.settings.image_shape,
show_secondary_image: section.settings.show_secondary_image,
show_vendor: section.settings.show_vendor,
show_rating: section.settings.show_rating,
skip_styles: skip_card_product_styles,
section_id: section.id,
quick_add: section.settings.quick_add
%}
</li>
{%- assign skip_card_product_styles = true -%}
{%- endfor -%}
{% endpaginate %}
{%- else -%}
{%- for i in (1..section.settings.columns_desktop) -%}
<li
Expand Down Expand Up @@ -144,7 +149,7 @@
%}
</li>
{%- endfor -%}
{%- endfor -%}
{%- endif -%}
</ul>
{%- if show_mobile_slider or show_desktop_slider -%}
<div class="slider-buttons">
Expand Down Expand Up @@ -197,7 +202,7 @@
</div>
</div>

{% schema %}

Check notice on line 205 in sections/featured-collection.liquid

View workflow job for this annotation

GitHub Actions / Theme Check Report

sections/featured-collection.liquid#L205

[SchemaJsonFormat] JSON formatting could be improved
{
"name": "t:sections.featured-collection.name",
"tag": "section",
Expand Down
Loading