N+1 queries with meilisearch #400
-
Don't know if this is pagy or meilisearch specific but looking to limit N+1 queries when executing searches. Where would I add the required includes? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Why your intention to limit N+1 queries would have anything to do with where to add the required includes? |
Beta Was this translation helpful? Give feedback.
-
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 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 with the N+1? |
Beta Was this translation helpful? Give feedback.
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 theActiveRecord_Relation.include Pagy::Meilisearch
in the model.Then you can
Are you still having trouble w…