Commit 25403f97 authored by Tan Le's avatar Tan Le

Use a more succinct syntax to count by queues

`tally` is introduced since Ruby 2.7 and also adds small performance
gain compared to the old approach (~ 1.6x).
parent 6f5b2839
......@@ -111,7 +111,7 @@ module Gitlab
end
def self.count_by_queue(queues)
queues.each_with_object(Hash.new(0)) { |element, hash| hash[element] += 1 }
queues.tally
end
def self.proc_details(counts)
......
......@@ -123,6 +123,14 @@ RSpec.describe Gitlab::SidekiqCluster do
end
end
describe '.count_by_queue' do
it 'tallies the queue counts' do
queues = [%w(foo), %w(bar baz), %w(foo)]
expect(described_class.count_by_queue(queues)).to eq(%w(foo) => 2, %w(bar baz) => 1)
end
end
describe '.concurrency' do
using RSpec::Parameterized::TableSyntax
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment