Skip to content

New cop to suggest using bulk enqueue methods #1517

@fatkodima

Description

@fatkodima

Instead of enqueuing jobs in a loop or sending emails in a loop, it is much more efficient to enqueue them all at once.

# bad
ids.each do |id|
  SomeJob.perform_later(id)
end

# good
jobs = ids.map { |id| SomeJob.new(id) }
ActiveJob.perform_all_later(jobs)

Similar ActionMailer's deliver_all_later. Possibly can also check for sidekiq's perform_bulk.

I see a lot of places in my app where this is violated and recently improved a lot of code paths in terms of performance by using these methods.

I already have this cop implemented, so can contribute if accepted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions