perf(imports): Bulk import CSV transactions #1962
Reference in New Issue
Block a user
Delete Branch "import-performance"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Bulk import transactions from CSV instead of importing each row at a time resulting in a optimization in performance and faster imports
Fixes: #1846.
Since we're using Postgres, I think we could use the
recursiveoption here to avoid doing all the matching logic and still leverage the benefits of activerecord-import:https://github.com/zdennis/activerecord-import?tab=readme-ov-file#recursive
I've been playing around with it and it doesn't seem like it works well with delegated types. Even with the
recursiveoption, I get the error: "Validation failed: Entryable must exist". Rails is expecting theEntryableto already be in the database with an ID.I've optimized the code a bit so that we are aren't matching between arrays.
@Joelute looks like
activerecord-import'srecursiveoption doesn't handlebelongs_torelationships; onlyhas_manyandhas_one. I got things working by flipping the association:The main reason I'd like to use this
recursiveoption is because I think it is the primary benefit we're getting from the additional gem. If we're not using it, I'd prefer to remove the gem and useinsert_allfor the bulk updates.Interesting, I should take a look into how the recursive option works and the benefits of it. I've updated the PR to reflect those changes.
Looks good! Thanks for tackling this.
Just rebased the branch with the new changes.