From 60d08ab5656687d254cec1b02f6d27eecd7ba3ad Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 26 Apr 2017 13:12:55 +0200 Subject: [PATCH] improves query on admin stats controller --- app/controllers/admin/stats_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index 6a2021592..9989da796 100644 --- a/app/controllers/admin/stats_controller.rb +++ b/app/controllers/admin/stats_controller.rb @@ -21,8 +21,9 @@ class Admin::StatsController < Admin::BaseController @user_ids_who_voted_proposals = ActsAsVotable::Vote.where(votable_type: 'Proposal').distinct.count(:voter_id) @user_ids_who_didnt_vote_proposals = @verified_users - @user_ids_who_voted_proposals @spending_proposals = SpendingProposal.count - @budgets = Budget.where.not(phase: 'finished').count - @investments = Budget.where.not(phase: 'finished').collect(&:investments).flatten.count + budgets_ids = Budget.where.not(phase: 'finished').pluck(:id) + @budgets = budgets_ids.size + @investments = Budget::Investment.where(budget_id: budgets_ids).count end def proposal_notifications