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)
1956
1956
freeze_time
1957
1957
----
1958
1958
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
+
1959
1983
== Managing Processes
1960
1984
1961
1985
=== Foreman [[foreman]]
You can’t perform that action at this time.
0 commit comments