Search code examples
ruby-on-railsactiverecordbulkinsert

Bulk Insert records into Active Record table


I found that my Model.create! statements were taking a very long time to run when I added a large number of records at once. Looked at ActiveRecord-Import but it didn't work with an array of hashes (which is what I have and which I think is pretty common). How can I improve the performance?


Solution

  • I started running into problems with large numbers of records (> 10000), so I modified the code to work in groups of 1000 records at a time. Here is a link to the new code:

    https://gist.github.com/jackrg/76ade1724bd816292e4e