diff --git a/contentcuration/contentcuration/models.py b/contentcuration/contentcuration/models.py index 690325fc3c..9c366ed787 100644 --- a/contentcuration/contentcuration/models.py +++ b/contentcuration/contentcuration/models.py @@ -22,6 +22,7 @@ from django.core.mail import send_mail from django.core.validators import MaxValueValidator from django.core.validators import MinValueValidator +from django.db import connection from django.db import IntegrityError from django.db import models from django.db.models import Count @@ -261,9 +262,13 @@ def hard_delete_user_related_data(self): editable_channels_user_query, field="id")).filter(num_editors=1, public=False) # Point sole editor non-public channels' contentnodes to orphan tree to let - # our garbage collection delete the nodes and underlying files. - ContentNode._annotate_channel_id(ContentNode.objects).filter(channel_id__in=list( - non_public_channels_sole_editor.values_list("id", flat=True))).update(parent_id=settings.ORPHANAGE_ROOT_ID) + # our garbage collection delete the nodes and underlying file. + tree_ids_to_update = non_public_channels_sole_editor.values_list('main_tree__tree_id', flat=True) + + for tree_id in tree_ids_to_update: + ContentNode.objects.filter(tree_id=tree_id).update(parent_id=settings.ORPHANAGE_ROOT_ID) + + logging.debug("Queries after updating content nodes parent ID: %s", connection.queries) # Hard delete non-public channels associated with this user (if user is the only editor). non_public_channels_sole_editor.delete()