Skip to content

Commit

Permalink
Remove orphaned tags (#6335)
Browse files Browse the repository at this point in the history
* Bump django-taggit to 6.1.0

* Curate list of existing tags

* remove merging of fuzzy-matching tags

---------

Co-authored-by: Ryan Johnson <[email protected]>
  • Loading branch information
akatsoulas and escattone authored Nov 6, 2024
1 parent 9915962 commit 99e0c88
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
40 changes: 40 additions & 0 deletions kitsune/questions/migrations/0018_auto_20241105_0532.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Django 4.2.16 on 2024-11-05 05:32
from django.db import migrations


def remove_orphaned_and_archived_tags(apps, schema_editor):
Tag = apps.get_model("taggit", "Tag")
TaggedItem = apps.get_model("taggit", "TaggedItem")
Question = apps.get_model("questions", "Question")
ContentType = apps.get_model("contenttypes", "ContentType")

orphaned_tags = Tag.objects.filter(taggit_taggeditem_items__isnull=True)
orphaned_tags.delete()

question_content_type = ContentType.objects.get_for_model(Question)
archived_tag_ids = TaggedItem.objects.filter(
content_type=question_content_type,
object_id__in=Question.objects.filter(is_archived=True).values_list("id", flat=True),
).values_list("tag_id", flat=True)

non_archived_tag_ids = TaggedItem.objects.filter(
content_type=question_content_type,
object_id__in=Question.objects.filter(is_archived=False).values_list("id", flat=True),
).values_list("tag_id", flat=True)

exclusively_archived_tag_ids = set(archived_tag_ids) - set(non_archived_tag_ids)
exclusively_archived_tags = Tag.objects.filter(id__in=exclusively_archived_tag_ids)
exclusively_archived_tags.delete()


def backwards(apps, schema_editor):
pass


class Migration(migrations.Migration):

dependencies = [
("questions", "0017_question_update_topic_counter"),
]

operations = [migrations.RunPython(remove_orphaned_and_archived_tags, backwards)]
10 changes: 4 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ twython = "^3.9.1"
translate-toolkit = "^3.12.1"
django-ratelimit = "^4.1.0"
django-storages = {version = "^1.14.2", extras = ["google"]}
django-taggit = "5.0.1"
django-taggit = "^6.1.0"
django-user-agents = "^0.4.0"
django-watchman = "1.3.0"
premailer = "^3.10.0"
Expand Down

0 comments on commit 99e0c88

Please sign in to comment.