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

Add support for raw_import flag #375

Merged
merged 1 commit into from
Apr 26, 2016
Merged

Conversation

DNNX
Copy link
Contributor

@DNNX DNNX commented Apr 21, 2016

A new raw_import option was added. Basically, it allows to avoid unnecessary serialization->deserialization cycles when it matters. Often, a lot of time is spent on creating AR objects, typecasting fields, etc. But eventually, it all gets converted back to strings. So why waste resources on unnecessary conversions. Raw Import is added just for this purpose. On one of our indexes, using this feature shanked index reset time from 7.5 minutes to 4.5 minutes.

The details on how to use this feature can be found in the updated documentation.

@@ -49,6 +55,17 @@ def scope_where_ids_in(scope, ids)
scope.where(target_id.in(Array.wrap(ids)))
end

def raw_default_scope_where_ids_in(ids)
sql = default_scope.where(target_id.in(Array.wrap(ids))).to_sql
Copy link
Contributor

Choose a reason for hiding this comment

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

default_scope_where_ids_in(ids).to_sql?

@DNNX DNNX force-pushed the raw-import branch 2 times, most recently from 3037516 to b7abbd9 Compare April 26, 2016 09:17
@DNNX
Copy link
Contributor Author

DNNX commented Apr 26, 2016

@pyromaniac please have a look

@DNNX DNNX changed the title [WIP] Add support for raw_import flag Add support for raw_import flag Apr 26, 2016
This flag allows to avoid ActiveRecord instantiation
on big imports, which can speed up chewing time significantly.
@pyromaniac pyromaniac merged commit b6f1749 into toptal:master Apr 26, 2016
@perlun
Copy link

perlun commented Oct 13, 2016

@DNNX - thanks for a great feature. I'm probably a bit stupid (very newbie on ActiveRecord et al) but I am struggling to get it working based on the information you wrote there in the docs, but I cannot really understand how to get my head around it.

I have my ActiveRecord model set up etc, and via the activerecord-import gem an extra #import method is provided (which allows you to do do bulk-import into e.g. Postgres databases, which in turn speeds things up quite significantly). But how does the Chewy import method fit into the whole picture? Any suggestions would be highly appreciated.

levent pushed a commit to levent/chewy that referenced this pull request Nov 1, 2016
This flag allows to avoid ActiveRecord instantiation
on big imports, which can speed up chewing time significantly.
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.

3 participants