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.
This commit is contained in:
Javi Martín
2019-04-11 11:17:51 +02:00
parent 13dd77dd1b
commit e2a3398ec0

View File

@@ -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