Skip to content

Commit 8f343fa

Browse files
authored
Take already migrated follows into account (#4162)
See issue described here: #4160 (comment)
1 parent bf9865c commit 8f343fa

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

app/grandchallenge/discussion_forums/management/commands/migrate_follows.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ def handle(self, *args, **options):
2727
n_updated = 0
2828
batch_size = 1000
2929

30+
existing_follows = set(
31+
Follow.objects.filter(
32+
content_type__in=[new_forum_ct, new_topic_ct]
33+
).values_list("content_type__pk", "object_id", "user__pk")
34+
)
35+
3036
for follow in (
3137
Follow.objects.filter(
3238
content_type__in=[old_forum_ct, old_forumtopic_ct]
@@ -57,7 +63,14 @@ def handle(self, *args, **options):
5763
follow.object_id = topic.pk
5864
follow.content_type = new_topic_ct
5965

60-
follows_to_update.append(follow)
66+
key = (
67+
follow.content_type.pk,
68+
str(follow.object_id),
69+
follow.user.pk,
70+
)
71+
if key not in existing_follows:
72+
follows_to_update.append(follow)
73+
existing_follows.add(key)
6174

6275
if len(follows_to_update) >= batch_size:
6376
Follow.objects.bulk_update(

0 commit comments

Comments
 (0)