Skip to content

Commit 96288e6

Browse files
committed
Try adding tags for all patches again
1 parent 795264f commit 96288e6

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

pgcommitfest/commitfest/migrations/0016_migrate_topics_to_tags.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@
66
def create_missing_tags_and_map_topics(apps, schema_editor):
77
"""
88
Create missing tags and map existing topics to appropriate tags.
9-
Only applies to patches in active (open or in-progress) commitfests.
109
"""
1110
Tag = apps.get_model("commitfest", "Tag")
1211
Patch = apps.get_model("commitfest", "Patch")
1312
Topic = apps.get_model("commitfest", "Topic")
14-
PatchOnCommitFest = apps.get_model("commitfest", "PatchOnCommitFest")
15-
16-
# CommitFest status constants (matching models.py)
17-
STATUS_OPEN = 2
18-
STATUS_INPROGRESS = 3
13+
PatchTag = Patch.tags.through
1914

2015
# Create missing tags
2116
Tag.objects.get_or_create(
@@ -55,30 +50,25 @@ def create_missing_tags_and_map_topics(apps, schema_editor):
5550
# chosen there.
5651
}
5752

58-
# Get patch IDs that are in active commitfests (open or in-progress)
59-
active_patch_ids = set(
60-
PatchOnCommitFest.objects.filter(
61-
commitfest__status__in=[STATUS_OPEN, STATUS_INPROGRESS]
62-
).values_list("patch_id", flat=True)
63-
)
64-
6553
# Apply tags to existing patches based on their topics
6654
for topic_name, tag_name in topic_tag_mapping.items():
6755
try:
6856
topic = Topic.objects.get(topic=topic_name)
6957
tag = Tag.objects.get(name=tag_name)
7058

71-
# Get patches with this topic that are in active commitfests
72-
patches_with_topic = Patch.objects.filter(
73-
topic=topic, id__in=active_patch_ids
59+
# Get all patch IDs with this topic
60+
patch_ids = list(
61+
Patch.objects.filter(topic=topic).values_list("id", flat=True)
7462
)
7563

76-
# Add the corresponding tag to each patch
77-
for patch in patches_with_topic:
78-
patch.tags.add(tag)
64+
# Bulk create the patch-tag relationships
65+
PatchTag.objects.bulk_create(
66+
[PatchTag(patch_id=pid, tag_id=tag.id) for pid in patch_ids],
67+
ignore_conflicts=True,
68+
)
7969

8070
print(
81-
f"Mapped {patches_with_topic.count()} patches from topic '{topic_name}' to tag '{tag_name}'"
71+
f"Mapped {len(patch_ids)} patches from topic '{topic_name}' to tag '{tag_name}'"
8272
)
8373

8474
except Topic.DoesNotExist:

0 commit comments

Comments
 (0)