From ffc8ed738d449239847458f52741067a1064ddfc Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 9 Mar 2021 15:39:21 +0000 Subject: [PATCH 1/3] Bump rubocop-performance from 1.7.1 to 1.10.1 Bumps [rubocop-performance](https://github.com/rubocop/rubocop-performance) from 1.7.1 to 1.10.1. - [Release notes](https://github.com/rubocop/rubocop-performance/releases) - [Changelog](https://github.com/rubocop/rubocop-performance/blob/master/CHANGELOG.md) - [Commits](https://github.com/rubocop/rubocop-performance/compare/v1.7.1...v1.10.1) Signed-off-by: dependabot-preview[bot] --- Gemfile | 2 +- Gemfile.lock | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 21ac0174c..7bc7d2e42 100644 --- a/Gemfile +++ b/Gemfile @@ -108,7 +108,7 @@ group :development do gem "pronto-rubocop", "~> 0.11.1", require: false gem "pronto-scss", "~> 0.11.0", require: false gem "rubocop", "~> 0.93.1", require: false - gem "rubocop-performance", "~> 1.7.1", require: false + gem "rubocop-performance", "~> 1.10.1", require: false gem "rubocop-rails", "~> 2.9.1", require: false gem "rubocop-rspec", "~> 1.44.1", require: false gem "rvm1-capistrano3", "~> 1.4.0", require: false diff --git a/Gemfile.lock b/Gemfile.lock index c3b27accc..171d49822 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -553,8 +553,9 @@ GEM unicode-display_width (>= 1.4.0, < 2.0) rubocop-ast (1.9.0) parser (>= 3.0.1.1) - rubocop-performance (1.7.1) - rubocop (>= 0.82.0) + rubocop-performance (1.10.2) + rubocop (>= 0.90.0, < 2.0) + rubocop-ast (>= 0.4.0) rubocop-rails (2.9.1) activesupport (>= 4.2.0) rack (>= 1.1) @@ -771,7 +772,7 @@ DEPENDENCIES rollbar (~> 3.1.2) rspec-rails (~> 4.0) rubocop (~> 0.93.1) - rubocop-performance (~> 1.7.1) + rubocop-performance (~> 1.10.1) rubocop-rails (~> 2.9.1) rubocop-rspec (~> 1.44.1) rvm1-capistrano3 (~> 1.4.0) From e619ca992c7f062003c48ddf795ee26c1f5fdef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 10 Aug 2021 00:11:55 +0200 Subject: [PATCH 2/3] Add and apply Performance/Sum rubocop rule We're not adding it for performance reasons but because it simplifies the code. --- .rubocop.yml | 3 +++ app/models/budget/stats.rb | 16 ++++++++-------- app/models/legislation/process.rb | 2 +- .../microsoft/sentences_parser.rb | 2 +- lib/tasks/proposal_actions.rake | 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 5bb235a61..e9548346f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -217,6 +217,9 @@ Performance/EndWith: Performance/StartWith: Enabled: true +Performance/Sum: + Enabled: true + Rails/ActiveRecordCallbacksOrder: Enabled: true diff --git a/app/models/budget/stats.rb b/app/models/budget/stats.rb index f929246ea..2094bb1e8 100644 --- a/app/models/budget/stats.rb +++ b/app/models/budget/stats.rb @@ -54,7 +54,7 @@ class Budget::Stats end def total_votes - budget.ballots.pluck(:ballot_lines_count).reduce(0) { |sum, x| sum + x } + budget.ballots.pluck(:ballot_lines_count).sum end def total_selected_investments @@ -72,18 +72,18 @@ class Budget::Stats end groups[:total] = Hash.new(0) - groups[:total][:total_investments_count] = groups.map { |_k, v| v[:total_investments_count] }.sum - groups[:total][:total_participants_support_phase] = groups.map { |_k, v| v[:total_participants_support_phase] }.sum - groups[:total][:total_participants_vote_phase] = groups.map { |_k, v| v[:total_participants_vote_phase] }.sum - groups[:total][:total_participants_every_phase] = groups.map { |_k, v| v[:total_participants_every_phase] }.sum + groups[:total][:total_investments_count] = groups.sum { |_k, v| v[:total_investments_count] } + groups[:total][:total_participants_support_phase] = groups.sum { |_k, v| v[:total_participants_support_phase] } + groups[:total][:total_participants_vote_phase] = groups.sum { |_k, v| v[:total_participants_vote_phase] } + groups[:total][:total_participants_every_phase] = groups.sum { |_k, v| v[:total_participants_every_phase] } budget.headings.each do |heading| groups[heading.id].merge!(calculate_heading_stats_with_totals(groups[heading.id], groups[:total], heading.population)) end - groups[:total][:percentage_participants_support_phase] = groups.map { |_k, v| v[:percentage_participants_support_phase] }.sum - groups[:total][:percentage_participants_vote_phase] = groups.map { |_k, v| v[:percentage_participants_vote_phase] }.sum - groups[:total][:percentage_participants_every_phase] = groups.map { |_k, v| v[:percentage_participants_every_phase] }.sum + groups[:total][:percentage_participants_support_phase] = groups.sum { |_k, v| v[:percentage_participants_support_phase] } + groups[:total][:percentage_participants_vote_phase] = groups.sum { |_k, v| v[:percentage_participants_vote_phase] } + groups[:total][:percentage_participants_every_phase] = groups.sum { |_k, v| v[:percentage_participants_every_phase] } groups end diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 12b195cce..77240a13e 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -110,7 +110,7 @@ class Legislation::Process < ApplicationRecord end def total_comments - questions.sum(:comments_count) + draft_versions.map(&:total_comments).sum + questions.sum(:comments_count) + draft_versions.sum(&:total_comments) end def status diff --git a/lib/remote_translations/microsoft/sentences_parser.rb b/lib/remote_translations/microsoft/sentences_parser.rb index 9e48ca4ac..ae2711d68 100644 --- a/lib/remote_translations/microsoft/sentences_parser.rb +++ b/lib/remote_translations/microsoft/sentences_parser.rb @@ -18,6 +18,6 @@ module RemoteTranslations::Microsoft::SentencesParser end def characters_count(texts) - texts.map(&:size).reduce(:+) + texts.sum(&:size) end end diff --git a/lib/tasks/proposal_actions.rake b/lib/tasks/proposal_actions.rake index 8dfc3d245..a5670e23a 100644 --- a/lib/tasks/proposal_actions.rake +++ b/lib/tasks/proposal_actions.rake @@ -384,7 +384,7 @@ namespace :proposal_actions do 5 ] - votes_count = expected_supports.reduce(0.0) { |sum, x| sum + x } + votes_count = expected_supports.sum goal_votes = Setting["votes_for_proposal_success"].to_f cached_votes_up = 0 From db4451c7c2a2d5c1cbd45a5fd1e6bc3a8c7e4947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 10 Aug 2021 00:18:32 +0200 Subject: [PATCH 3/3] Add Performance/BlockGivenWithExplicitBlock rule We don't need to use `block_given?` since we specifically pass the block parameter, particularly since we added the Style/ExplicitBlockArgument rule in commit a102f3f0a. --- .rubocop.yml | 3 +++ app/components/concerns/header.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index e9548346f..367a8dde3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -205,6 +205,9 @@ Lint/UselessAssignment: Lint/Void: Enabled: true +Performance/BlockGivenWithExplicitBlock: + Enabled: true + Performance/CompareWithBlock: Enabled: true diff --git a/app/components/concerns/header.rb b/app/components/concerns/header.rb index 9b1b21937..aa9700c0d 100644 --- a/app/components/concerns/header.rb +++ b/app/components/concerns/header.rb @@ -17,7 +17,7 @@ module Header end tag.header do - safe_join([before, content_tag(heading_tag, title), (capture(&block) if block_given?)].compact) + safe_join([before, content_tag(heading_tag, title), (capture(&block) if block)].compact) end end