mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FIX: Cater for polls that can have multiple votes per user (#22297)
Cater for polls that can have multiple votes per user. This fixes an older UserMerge and migration which was intended to de-duplicate poll votes but did not account for "multiple" type polls.
This commit is contained in:
@ -171,15 +171,13 @@ after_initialize do
|
||||
on(:merging_users) do |source_user, target_user|
|
||||
DB.exec(<<-SQL, source_user_id: source_user.id, target_user_id: target_user.id)
|
||||
DELETE FROM poll_votes
|
||||
WHERE poll_id IN (
|
||||
SELECT poll_id
|
||||
FROM poll_votes
|
||||
WHERE user_id = :source_user_id
|
||||
INTERSECT
|
||||
SELECT poll_id
|
||||
WHERE user_id = :source_user_id
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM poll_votes
|
||||
WHERE user_id = :target_user_id
|
||||
) AND user_id = :source_user_id;
|
||||
AND poll_votes.poll_id = poll_votes.poll_id
|
||||
);
|
||||
|
||||
UPDATE poll_votes
|
||||
SET user_id = :target_user_id
|
||||
|
Reference in New Issue
Block a user