From 5e060e1f447d91436c18e164c4d32054a9a72d5f Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 2 May 2023 10:10:40 -0400 Subject: [PATCH] Fix Performance/Sum cop (#24788) --- .rubocop_todo.yml | 8 -------- app/lib/activity_tracker.rb | 2 +- app/models/trends/history.rb | 2 +- lib/paperclip/color_extractor.rb | 2 +- 4 files changed, 3 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a3b80f141bf..900bb82010c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -371,14 +371,6 @@ Performance/StartWith: Exclude: - 'app/lib/extractor.rb' -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: OnlySumOrWithInitialValue. -Performance/Sum: - Exclude: - - 'app/lib/activity_tracker.rb' - - 'app/models/trends/history.rb' - - 'lib/paperclip/color_extractor.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). Performance/TimesMap: Exclude: diff --git a/app/lib/activity_tracker.rb b/app/lib/activity_tracker.rb index 8829d8605f3..9160ef22a69 100644 --- a/app/lib/activity_tracker.rb +++ b/app/lib/activity_tracker.rb @@ -43,7 +43,7 @@ class ActivityTracker case @type when :basic - redis.mget(*keys).map(&:to_i).sum + redis.mget(*keys).sum(&:to_i) when :unique redis.pfcount(*keys) end diff --git a/app/models/trends/history.rb b/app/models/trends/history.rb index 83532e7bc8d..db368993372 100644 --- a/app/models/trends/history.rb +++ b/app/models/trends/history.rb @@ -11,7 +11,7 @@ class Trends::History end def uses - with_redis { |redis| redis.mget(*@days.map { |day| day.key_for(:uses) }).map(&:to_i).sum } + with_redis { |redis| redis.mget(*@days.map { |day| day.key_for(:uses) }).sum(&:to_i) } end def accounts diff --git a/lib/paperclip/color_extractor.rb b/lib/paperclip/color_extractor.rb index 2e8dc04fd8e..19529fb8a16 100644 --- a/lib/paperclip/color_extractor.rb +++ b/lib/paperclip/color_extractor.rb @@ -173,7 +173,7 @@ module Paperclip def palette_from_histogram(result, quantity) frequencies = result.scan(/([0-9]+)\:/).flatten.map(&:to_f) hex_values = result.scan(/\#([0-9A-Fa-f]{6,8})/).flatten - total_frequencies = frequencies.reduce(&:+).to_f + total_frequencies = frequencies.sum.to_f frequencies.map.with_index { |f, i| [f / total_frequencies, hex_values[i]] } .sort_by { |r| -r[0] }