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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user