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

[WIP] Use pluck instead of map #1571

Closed

Conversation

BobbyMcWho
Copy link
Contributor

Use in_batches.each with pluck in the AR case, so that we avoid loading all of the objects into memory when we're really just looking for ids here.

Mongoid supports pluck as of 3.0.1. I'm not sure what version searchkick targets, but it looks like latest Mongoid is 5.0+, so maybe worth dropping support for lower than 3.0.1?

This is a PR after a cursory read of the code and reading #1549, so please challenge any assumptions I've made.

I couldn't get tests running locally, it was unclear in the README#contributing section, so I may just not have ES running locally.

The client is unable to verify that the server is Elasticsearch. Some functionality may not be compatible if the server is running an unsupported product.
/Users/bobbymcdonald/.asdf/installs/ruby/3.0.3/lib/ruby/gems/3.0.0/gems/typhoeus-1.4.0/lib/typhoeus/adapters/faraday.rb:106:in `block in request': Server returned nothing (no headers, no data) (Faraday::ConnectionFailed)

@BobbyMcWho BobbyMcWho force-pushed the use-pluck-instead-of-map branch from e3ea9fb to ba1a6fe Compare June 29, 2022 15:15
@@ -109,7 +109,7 @@ def each_batch(relation, batch_size:)
# https://github.com/karmi/tire/blob/master/lib/tire/model/import.rb
# use cursor for Mongoid
items = []
relation.all.each do |item|
relation.all.pluck(:_id).each do |item|
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this be :_id or :id? I've not used Mongoid, and the changelog example used :_id, though the previous implementation in searchkick maps w/ :id

@ankane
Copy link
Owner

ankane commented Jul 4, 2022

Hey @BobbyMcWho, thanks for the PR. However, the full object is needed in some cases, and this isn't something I'd like to spend time on right now.

@ankane ankane closed this Jul 4, 2022
@BobbyMcWho
Copy link
Contributor Author

Alright, didn't see anywhere that the full object was needed since map was called w/ id and passed to the job creation.

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