Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent duplicate voting to same discussion #2925

Merged
merged 1 commit into from Apr 6, 2018

Conversation

nanaya
Copy link
Collaborator

@nanaya nanaya commented Apr 6, 2018

Forgot a unique index.

Fixes #2923.

Useful stuff:

DB::table('beatmap_discussion_votes')->groupBy(['user_id','beatmap_discussion_id'])->having('count(*)', '>', 1)->selectRaw('count(*), max(id), max(score), min(score), beatmap_discussion_id, user_id')->get();

// clean up
$a = DB::table('beatmap_discussion_votes')->groupBy(['user_id','beatmap_discussion_id'])->having('count(*)', '>', 1)->selectRaw('count(*), max(id), max(score), min(score), beatmap_discussion_id, user_id')->get()->pluck('max(id)')->toArray();
BeatmapDiscussionVote::whereIn('id', $a)->get()->each->delete();
php artisan kudosu:recalculate-discussions-grants

Copy link
Collaborator

@notbakaneko notbakaneko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the cleanup handle if they're more than 2 duplicates? Are there even any cases with more than 2?

@nanaya
Copy link
Collaborator Author

nanaya commented Apr 6, 2018

Just run multiple times.

@notbakaneko notbakaneko merged commit fb45fef into ppy:master Apr 6, 2018
@nanaya
Copy link
Collaborator Author

nanaya commented Apr 6, 2018

The hack isn't supposed to be all that smart

@ppy ppy deleted a comment from notbakaneko Apr 6, 2018
@nanaya nanaya deleted the unique_votes branch May 21, 2018 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants