Files
danbooru/script/fixes/075_delete_duplicate_post_votes.rb
evazion 0a8fe506b4 posts: add script to remove duplicate votes.
There were 67 duplicate votes in the production database.
2021-01-29 02:09:30 -06:00

15 lines
415 B
Ruby
Executable File

#!/usr/bin/env ruby
require_relative "../../config/environment"
PostVote.transaction do
PostVote.group(:post_id, :user_id).having("count(*) > 1").count.each do |(post_id, user_id), count|
votes = PostVote.where(post_id: post_id, user_id: user_id).order(:id)
# Remove all but the first duplicate vote.
dupe_votes = votes.drop(1)
dupe_votes.each { p _1 }
dupe_votes.each(&:destroy)
end
end