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
|
private
|
||||||
|
|
||||||
def participant_ids
|
def participant_ids
|
||||||
voters.pluck(:user_id)
|
voters
|
||||||
end
|
end
|
||||||
|
|
||||||
def voters
|
def voters
|
||||||
@voters ||= poll.voters
|
@voters ||= poll.voters.select(:user_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def recounts
|
def recounts
|
||||||
|
|||||||
Reference in New Issue
Block a user