-
Notifications
You must be signed in to change notification settings - Fork 760
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
Unscope the search_import scope in-case I'm indexing some attrs, #1639
Comments
I faced similar situation and in my case, I am performing partial reindex on prices columns and for that It eager loads all the association which is defined in Searchkick.indexer.queue(YourDbRecords.map do |r|
Searchkick::RecordData.new(YourModel.searchkick_index, r).update_data(partial_data_method_name)
end
) Reference: https://github.com/ankane/searchkick/blob/master/lib/searchkick/index.rb#L167 @ankane - We can easily implement this by introducing new flag on configuration level or we can also introduce new method for this. And I am happy to raise PR for this. This is valid case because I am performing partial data reindexing on lots of data and that too frequently and I can't use |
If you're reindexing an I've used this technique to avoid unnecessary queries when partially reindexing a model. Here's a basic example. Modelclass Post < ApplicationRecord
has_many :comments
has_many :reactions
scope :comments_search_import, -> { includes(:comments) }
scope :reactions_search_import, -> { includes(:reactions) }
# Combine the partial scopes to create the full scope
scope :search_import, -> { comments_search_import.reactions_search_import }
private
def comments_data
{ commenter_ids: comments.map(&:user_id).uniq }
end
def reactions_data
{ reactor_ids: reactions.map(&:user_id).uniq }
end
def search_data
comments_data.merge(reactions_data)
end
end UsageGiven an Post.reindex(:comments_data, scope: :comments_search_import) or Post.reindex(:reactions_data, scope: :reactions_search_import) Referencesearchkick/lib/searchkick/relation_indexer.rb Lines 9 to 15 in dd63a30
|
First
Done
Is your feature request related to a problem? Please describe.
I have a search_import scope like
I don't want to eager_load the apps when I'm only indexing let's say the domain name (FYI: domain has_many apps). How to unscope it
here's my search_data method
Describe the solution you'd like
The text was updated successfully, but these errors were encountered: