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

Avoid Elasticsearch index updates when passing empty reflections #620

Merged
merged 1 commit into from
Dec 22, 2017

Conversation

robertasg
Copy link

Passing [] or another equivalent of an empty reflection to Index.import! makes two requests to the corresponding Elasticsearch index. GET /index and PUT /index to ensure whether the index exists, and to update the index.

Given a complicated record which triggers many Chewy index updates on associations, this might result in N+1 requests, which might be undesired.

This change adds avoids these requests whenever the reflection is empty.

@@ -126,6 +126,7 @@ def compose(object, crutches = nil, fields: [])
private

def import_routine(*args)
return if args.first.blank? && !args.first.nil?
Copy link
Contributor

Choose a reason for hiding this comment

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

What if only the options are passed?
It probably makes sense to do this check after args.extract_options!

Copy link
Author

Choose a reason for hiding this comment

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

In that case, given that options aren't empty, this would work the same as Index.import! (without objects, with imports everything under the scope). Right?

Copy link
Author

Choose a reason for hiding this comment

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

I don't mind changing this to make it less confusing though.

@pyromaniac pyromaniac merged commit e2a62dd into master Dec 22, 2017
@pyromaniac pyromaniac deleted the avoid-index-updates-with-empty-reflections branch December 22, 2017 15:30
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.

2 participants