-
Notifications
You must be signed in to change notification settings - Fork 6
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
Adding support for mysql upsert via AR import #18
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
adamstegman
reviewed
Aug 6, 2021
Co-authored-by: Adam ⚛ Stegman <astegman@onemedical.com>
…scrubbable into update_to_use_import
I tweaked the way we determine which update method we use. Instead of being aware of the application database and gem configuration, it is now explicitly configured through the initializer or through an environment variable. |
adamstegman
reviewed
Aug 11, 2021
adamstegman
approved these changes
Aug 12, 2021
adamstegman
added a commit
that referenced
this pull request
Jul 8, 2024
Callbacks should be around the update, not just retrieving scrubbed values. I think this should have been moved in #18, but wasn't caught.
adamstegman
added a commit
that referenced
this pull request
Jul 9, 2024
Callbacks should be around the update, not just retrieving scrubbed values. I think this should have been moved in #18, but wasn't caught.
adamstegman
added a commit
that referenced
this pull request
Jul 10, 2024
Callbacks should be around the update, not just retrieving scrubbed values. I think this should have been moved in #18, but wasn't caught.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The existing scrubbing process relies on singular update statements to apply the changes to the models. This is effective but very time consuming if you are attempting to scrub a large amount of data.
MySQL, PostgreSQL and SQLite all support some variation of bulk updating via an upsert operation. Thankfully
activerecord-import
has incorporated support for this making it easy to implement. https://github.com/zdennis/activerecord-import#duplicate-key-updateSo at the core of this change, we are adding support to apply scrubbed changes via a bulk upsert versus update commands.
The performance implications of this change are significant. In a test against a table with 700,000 rows, the upsert approach was approximately 5x faster (5m13.113s vs 27m49.008s).
Additional changes in this PR are around reorganizing the code to create one distinct implementation path between
scrub
andscrub:model
and decomposing some of the layers for better separation of concerns.Note: Because the
activerecord-import
implementations for MySQL and PostgreSQL are slightly different, I have only added support for MySQL at this time.