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