Skip to content

Commit

Permalink
fix vote
Browse files Browse the repository at this point in the history
  • Loading branch information
hooopo committed Oct 31, 2019
1 parent 9116ca0 commit 1049763
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/post_revisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "edit_rate_limiter"
require 'post_locker'
require 'onpdiff'

class PostRevisor

Expand Down
29 changes: 19 additions & 10 deletions plugins/poll/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,26 @@ def serialized_voters(poll, opts = {})
result = { option_digest => user_hashes }
else
votes = DB.query <<~SQL
SELECT digest, user_id
SELECT digest,
user_id
FROM (
SELECT digest
, user_id
, ROW_NUMBER() OVER (PARTITION BY poll_option_id ORDER BY pv.created_at) AS row
FROM poll_votes pv
JOIN poll_options po ON pv.poll_option_id = po.id
WHERE pv.poll_id = #{poll.id}
AND po.poll_id = #{poll.id}
) v
WHERE row BETWEEN #{offset} AND #{offset + limit}
SELECT digest,
user_id,
@row_number:=CASE WHEN @poll_option_id=poll_option_id THEN @row_number+1 ELSE 1 END AS row,
@poll_option_id:=poll_option_id
FROM (
SELECT digest
, user_id
, pv.poll_option_id
, pv.created_at
FROM poll_votes pv
JOIN poll_options po ON pv.poll_option_id = po.id
WHERE pv.poll_id = #{poll.id}
AND po.poll_id = #{poll.id}
) v, (SELECT @row_number:=0,@poll_option_id:='') AS t
ORDER BY poll_option_id, created_at
) vv
WHERE row BETWEEN #{offset} AND #{offset + limit}
SQL

user_ids = votes.map(&:user_id).uniq
Expand Down

0 comments on commit 1049763

Please sign in to comment.