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

Trying to use Pagy pagination with Chewy, running into autoloading will_paginate gem #886

Open
dlegr250 opened this issue May 9, 2023 · 0 comments

Comments

@dlegr250
Copy link

dlegr250 commented May 9, 2023

Is your feature request related to a problem? Please describe.

I'm trying to implement the Pagy pagination gem with Chewy, but Chewy automatically includes kaminari and/or will_paginate if they are included in the project, and this built-in pagination is used behind-the-scenes automatically. The solution I've tried with some success is to make sure no other pagination gems are included, and then use Pagy with Chewy via:

chewy_query = SomeIndex.query(...)
@pagy, @records = Pagy.new(chewy_query.objects, page: 1, items: 50, count: chewy_query.total)

The specific issue is that pagination gems like will_paginate are automatically included and forced to be used if they are in the project, meaning I cannot switch from will_paginate to Pagy or another pagination alternative piece-by-piece, but must instead do an all-or-nothing approach.

Describe the solution you'd like

It would be nice to have an initializer for Chewy that sets the pagination gem to be used explicitly, and use none if none is provided. The reason I want to use Pagy is because it has a smaller memory footprint on pagination, and if you have a site that does a lot of Elasticsearch searches, decreasing the memory footprint a little bit pays off a lot in the long run.

Describe alternatives you've considered

Pagy works with elasticsearch-rails itself, but I like using Chewy because you add a lot of value and features! So getting rid of Chewy is a no-go for my team.

I have a solution that "seems" to work (listed above), but I'm not sure if it's the best implementation for trying to add Pagy pagination to Chewy. I was hoping there would have been a more plugin-style approach to pagination instead of using only kaminari or will_paginate.

I'm also looking at trying to reverse engineer those pagination modules that are listed in the Chewy pagination code, but I have to track down what calls belong to Chewy and which belong to the pagination gems themselves to see how I would implement something similar for Pagy.

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

No branches or pull requests

1 participant