From e2a3398ec06b7ca29b2900db42c09b745ce393e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 11 Apr 2019 11:17:51 +0200 Subject: [PATCH] Increase poll stats performance Using SQL's `select` instead of converting the records to a ruby array increases performance dramatically when there are thousands of records. For a poll with 200000 voters, calculating stats took more than 7 minutes, and now it takes less than 2 minutes. --- app/models/poll/stats.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/poll/stats.rb b/app/models/poll/stats.rb index ea075e6c9..d7c9826c5 100644 --- a/app/models/poll/stats.rb +++ b/app/models/poll/stats.rb @@ -92,11 +92,11 @@ class Poll::Stats private def participant_ids - voters.pluck(:user_id) + voters end def voters - @voters ||= poll.voters + @voters ||= poll.voters.select(:user_id) end def recounts