Skip to content

N+1 queries with meilisearch #400

Closed Answered by brunoocasali
coder2000 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @coder2000 I think we discussed that in the Meilisearch repo meilisearch/meilisearch-rails#133 (comment)

I'm not sure where I misread the discussion, but I thought you understood where to put the includes. Also, you must add the ActiveRecord_Relation.include Pagy::Meilisearch in the model.

class Restaurant < ApplicationRecord
  has_many :reviews, dependent: :destroy

  include MeiliSearch::Rails
  extend Pagy::Meilisearch
  ActiveRecord_Relation.include Pagy::Meilisearch # <--- this line

  meilisearch ...
end

Then you can

restaurants = Restaurant.includes(:reviews).pagy_search(params[:query])
@pagy, @restaurants = pagy_meilisearch(restaurants, items: 25)

Are you still having trouble w…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
4 replies
@coder2000
Comment options

@coder2000
Comment options

@ddnexus
Comment options

@ddnexus
Comment options

Comment options

You must be logged in to vote
2 replies
@coder2000
Comment options

@brunoocasali
Comment options

Answer selected by ddnexus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants