File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -1956,6 +1956,30 @@ travel_to(Time.current.to_time)
19561956freeze_time
19571957----
19581958
1959+ == Performance
1960+
1961+ === Enqueuing Many Jobs at Once [[enqueuing-many-jobs]]
1962+
1963+ Prefer enqueuing many jobs and emails at once instead of one by one in a loop.
1964+ This can greatly reduce the number of round-trips to the queue datastore.
1965+
1966+ [source,ruby]
1967+ ----
1968+ # bad
1969+ ids.each { |id| MyJob.perform_later(id) }
1970+
1971+ # good
1972+ jobs = ids.map { |id| MyJob.new(id) }
1973+ ActiveJob.perform_all_later(jobs)
1974+
1975+ # bad
1976+ users.each { |user| Notifier.welcome(user).deliver_later }
1977+
1978+ # good
1979+ emails = users.map { |user| Notifier.welcome(user) }
1980+ ActionMailer.deliver_all_later(emails)
1981+ ----
1982+
19591983== Managing Processes
19601984
19611985=== Foreman [[foreman]]
You can’t perform that action at this time.
0 commit comments