Delayed Work Delays

I am optimizing my SQL queries on my heroku server, so I can speed up work on one specific query. Now I mainly look at compressing all INSERT queries into as few queries as possible.

At some point in my code, I have the following:

jobs.each do |j| Delayed::Job.enqueue j end 

I found out that each iteration sends BEGIN, INSERT, COMMIT to db. This jobs array can have from several to several hundred objects. I was looking for a way to batch insert slow-motion jobs, but couldn't find anything. Any idea on how to achieve this?

+4
source share
2 answers

I ended up infecting my User object that had the jobs attribute. So 1 insert instead of jobs.length inserts.

+1
source

For a long time, I used AR extensions to insert massive data from models into a database.

This was on Rails 2.3.x, however, be careful that there are currently different versions depending on the version of Rails: http://www.continuousthinking.com/tags/arext

I'm not sure how Delayed :: Job works, but guessing from your example, I would suggest that it inserts a record for one job into a table, which then serves as a queue. You can expand this using AR-Extensions to assemble all of these models and insert all tasks at once.

+1
source

Source: https://habr.com/ru/post/1338017/


All Articles