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

2 participants
@nanaya
Collaborator

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
@notbakaneko

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

@nanaya

This comment has been minimized.

Collaborator

nanaya commented Apr 6, 2018

Just run multiple times.

@notbakaneko notbakaneko merged commit fb45fef into ppy:master Apr 6, 2018

2 checks passed

continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@nanaya

This comment has been minimized.

Collaborator

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 nanaya:unique_votes branch May 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment