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

Deprecate pagination in searcher #2119

Merged

Conversation

cbrunsdon
Copy link
Contributor

This deprecates doing pagination in the base searcher and instead pushes the responsibility onto the caller (in our cases the controllers).

We don't gain anything from doing the pagination inside the searcher, and it doesn't have anything to do with the core goal of it (searching).

Also throws the explicit dependencies on kaminari on frontend and backend (as they call kaminari functions).

It shouldn't be the searcher's responsibility to also handle how
pagination is happening.
@@ -9,8 +9,8 @@ def show
@taxon = Spree::Taxon.find_by!(permalink: params[:id])
return unless @taxon

@searcher = build_searcher(params.merge(taxon: @taxon.id, include_images: true))
@products = @searcher.retrieve_products
@searcher = build_searcher(params.merge(taxon: @taxon.id, include_images: true).reject { |k, v| ["per_page", "page"].include?(k) } )

Choose a reason for hiding this comment

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

Unused block argument - v. If it's necessary, use _ or _v as an argument name to indicate that it won't be used.

@@ -9,8 +9,8 @@ class ProductsController < Spree::StoreController
respond_to :html

def index
@searcher = build_searcher(params.merge(include_images: true))
@products = @searcher.retrieve_products
@searcher = build_searcher(params.merge(include_images: true).reject { |k, v| ["per_page", "page"].include?(k) } )

Choose a reason for hiding this comment

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

Unused block argument - v. If it's necessary, use _ or _v as an argument name to indicate that it won't be used.


per_page = params[:per_page].to_i
@properties[:per_page] = per_page > 0 ? per_page : Spree::Config[:products_per_page]
@properties[:page] = (params[:page].to_i <= 0) ? 1 : params[:page].to_i

Choose a reason for hiding this comment

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

Omit parentheses for ternary conditions.

@@ -9,8 +9,8 @@ def show
@taxon = Spree::Taxon.find_by!(permalink: params[:id])
return unless @taxon

@searcher = build_searcher(params.merge(taxon: @taxon.id, include_images: true))
@products = @searcher.retrieve_products
@searcher = build_searcher(params.merge(taxon: @taxon.id, include_images: true).reject { |k, v| ["per_page", "page"].include?(k) } )

Choose a reason for hiding this comment

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

Unused block argument - v. If it's necessary, use _ or _v as an argument name to indicate that it won't be used.

@@ -9,8 +9,8 @@ class ProductsController < Spree::StoreController
respond_to :html

def index
@searcher = build_searcher(params.merge(include_images: true))
@products = @searcher.retrieve_products
@searcher = build_searcher(params.merge(include_images: true).reject { |k, v| ["per_page", "page"].include?(k) } )

Choose a reason for hiding this comment

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

Unused block argument - v. If it's necessary, use _ or _v as an argument name to indicate that it won't be used.


per_page = params[:per_page].to_i
@properties[:per_page] = per_page > 0 ? per_page : Spree::Config[:products_per_page]
@properties[:page] = (params[:page].to_i <= 0) ? 1 : params[:page].to_i

Choose a reason for hiding this comment

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

Omit parentheses for ternary conditions.

@cbrunsdon cbrunsdon force-pushed the deprecate_pagination_in_searcher branch 2 times, most recently from 4169eb5 to 6874572 Compare July 26, 2017 02:19
@@ -9,8 +9,9 @@ def show
@taxon = Spree::Taxon.find_by!(permalink: params[:id])
return unless @taxon

@searcher = build_searcher(params.merge(taxon: @taxon.id, include_images: true))
@products = @searcher.retrieve_products
binding.pry

Choose a reason for hiding this comment

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

Remove debugger entry point binding.pry.

@@ -9,8 +9,9 @@ class ProductsController < Spree::StoreController
respond_to :html

def index
@searcher = build_searcher(params.merge(include_images: true))
@products = @searcher.retrieve_products
binding.pry

Choose a reason for hiding this comment

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

Remove debugger entry point binding.pry.

@@ -9,8 +9,9 @@ def show
@taxon = Spree::Taxon.find_by!(permalink: params[:id])
return unless @taxon

@searcher = build_searcher(params.merge(taxon: @taxon.id, include_images: true))
@products = @searcher.retrieve_products
binding.pry

Choose a reason for hiding this comment

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

Remove debugger entry point binding.pry.

@@ -9,8 +9,9 @@ class ProductsController < Spree::StoreController
respond_to :html

def index
@searcher = build_searcher(params.merge(include_images: true))
@products = @searcher.retrieve_products
binding.pry

Choose a reason for hiding this comment

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

Remove debugger entry point binding.pry.

@cbrunsdon cbrunsdon force-pushed the deprecate_pagination_in_searcher branch from 6874572 to 0e23f24 Compare July 26, 2017 02:36
These two places are the only place we support the searcher on the
frontend
@cbrunsdon cbrunsdon force-pushed the deprecate_pagination_in_searcher branch from 0e23f24 to 8aa9c81 Compare July 26, 2017 02:57
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

A very good change. Should we add a changelog note?

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

Great change!

@jhawthorn
Copy link
Contributor

Should solidus_api also receive an explicit dependency as it calls kaminari functions?

We actually use kaminari on the frontend, backend, and api. We should
explicitely add it as a dependency
@cbrunsdon cbrunsdon force-pushed the deprecate_pagination_in_searcher branch from 8aa9c81 to 8a0e7cd Compare July 26, 2017 22:59
@cbrunsdon
Copy link
Contributor Author

Good call hawth, added.

@jhawthorn jhawthorn merged commit 1f46990 into solidusio:master Jul 27, 2017
@ahwong5
Copy link

ahwong5 commented Dec 9, 2017

@cbrunsdon You have omitted to update the home controller as well, therefore the products at frontend homepage has lost the ability to paginate.

And also when performing Search, it doesn't paginate as well. I'm not sure which file need to update.

Thanks.

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.

6 participants