Skip to content

Commit

Permalink
Fix Performance/Sum cop (mastodon#24788)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored and skerit committed Jul 7, 2023
1 parent 524052e commit c5ae71f
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 11 deletions.
8 changes: 0 additions & 8 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion app/lib/activity_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def sum(start_at, end_at = Time.now.utc)

case @type
when :basic
redis.mget(*keys).map(&:to_i).sum
redis.mget(*keys).sum(&:to_i)
when :unique
redis.pfcount(*keys)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/trends/history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(prefix, id, date_range)
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
Expand Down
2 changes: 1 addition & 1 deletion lib/paperclip/color_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def lighten_or_darken(color, by)
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] }
Expand Down

0 comments on commit c5ae71f

Please sign in to comment.