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

Runing import without passing it through ID fetcher #636

Closed
TikiTDO opened this issue Feb 23, 2018 · 5 comments
Closed

Runing import without passing it through ID fetcher #636

TikiTDO opened this issue Feb 23, 2018 · 5 comments

Comments

@TikiTDO
Copy link
Contributor

TikiTDO commented Feb 23, 2018

Given code like this:

  my_scope = MyMode.includes(:some_association).where(stuff: things)
  MyModelIndex::MyModel.import = my_scope

# Where MyModelIndex uses :some_association to generate a field.

The import will end performing one extra query to load some_association per instance of MyModel in the scope, instead of using the included data.

This happens because both import_scope here and import_objects here re-run a select, regardless of what I pass in. For a more complex index, this can translate to a bunch of queries per instance that I want to import.

The only way I can do this right now is by skipping any sort of external API, and just doing an import directly:

some_scope.find_each(batch_size: 1000) do |batch|
  routine = Chewy::Type::Import::Routine.new(SomeIndex::SomeModel, {})
  routine .process({index: batch})
end

I would really prefer not to have to resort to something like this, so would it be possible to introduce either a key that skips the re-import, or some way to customize the default_scope used when re-loading the data to be imported?

@pyromaniac
Copy link
Contributor

Ok, agree, how about to add import_objects method near the import method which will do the thing you need? Can you prepare a PR?

@pyromaniac
Copy link
Contributor

Or an option is also fine by me

@TikiTDO
Copy link
Contributor Author

TikiTDO commented Feb 23, 2018

I like the method idea. I'll poke at it today and send a PR with a POC.

@TikiTDO
Copy link
Contributor Author

TikiTDO commented Feb 23, 2018

Actually maybe a bit of both, to keep the same structure with the import_routine into import_(parallel|linear).

@rabotyaga
Copy link
Contributor

Closed in #753

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

No branches or pull requests

3 participants