-
Notifications
You must be signed in to change notification settings - Fork 94
Remove duplicate tag proposals #579
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
Open
Arapak
wants to merge
6
commits into
master
Choose a base branch
from
kr/remove-duplicate-tag-proposals
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8d9d100
add the constraints
Arapak 7438e86
add migration
Arapak a2d1375
feat: return bad request on duplicate tag
Arapak 913de18
feat: unit test for duplicate difficulty tag
Arapak 48fbf42
fix: mass_create_tool breaks uniqueness constraint on tag proposals
Arapak 52cbaed
feat: optimize deletion requests
Arapak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
oioioi/problems/migrations/0039_alter_algorithmtagproposal_unique_together_and_more.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # Generated by Django 5.2.7 on 2025-11-17 22:44 | ||
|
|
||
| from django.conf import settings | ||
| from django.db import migrations | ||
| from django.db.models import Count | ||
|
|
||
| def cleanup_duplicate_proposals(apps, schema_editor): | ||
| AlgorithmTagProposal = apps.get_model('problems', 'AlgorithmTagProposal') | ||
| DifficultyTagProposal = apps.get_model('problems', 'DifficultyTagProposal') | ||
|
|
||
| # Cleanup AlgorithmTagProposal | ||
| duplicates = ( | ||
| AlgorithmTagProposal.objects.values('problem', 'tag', 'user') | ||
| .annotate(count=Count('id')) | ||
| .filter(count__gt=1) | ||
| ) | ||
|
|
||
| for duplicate in duplicates: | ||
| AlgorithmTagProposal.objects.filter( | ||
| pk__in=AlgorithmTagProposal.objects.filter( | ||
| problem=duplicate["problem"], | ||
| tag=duplicate["tag"], | ||
| user=duplicate["user"] | ||
| ).values_list("id", flat=True)[1:] | ||
| ).delete() | ||
|
|
||
| # Cleanup DifficultyTagProposal | ||
| duplicates = ( | ||
| DifficultyTagProposal.objects.values('problem', 'user') | ||
| .annotate(count=Count('id')) | ||
| .filter(count__gt=1) | ||
| ) | ||
|
|
||
| for duplicate in duplicates: | ||
| DifficultyTagProposal.objects.filter( | ||
| pk__in=DifficultyTagProposal.objects.filter( | ||
| problem=duplicate["problem"], | ||
| user=duplicate["user"] | ||
| ).values_list("id", flat=True)[1:] | ||
| ).delete() | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('problems', '0038_alter_algorithmtaglocalization_language_and_more'), | ||
| migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython(cleanup_duplicate_proposals), | ||
| migrations.AlterUniqueTogether( | ||
| name='algorithmtagproposal', | ||
| unique_together={('problem', 'tag', 'user')}, | ||
| ), | ||
| migrations.AlterUniqueTogether( | ||
| name='difficultytagproposal', | ||
| unique_together={('problem', 'user')}, | ||
| ), | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you tried how fast it is on large data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some ideas how to make it more efficient: https://stackoverflow.com/questions/5877306/remove-duplicates-in-a-django-query
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
considering there are around ~300 rows to delete this is shouldn't be a problem, I added the optimization either way