Skip to content

Commit

Permalink
Merge pull request #4808 from ozer550/optimize-garbage-collection-com…
Browse files Browse the repository at this point in the history
…mand

optimize garabge collection command
  • Loading branch information
bjester authored Nov 14, 2024
2 parents d8f95b5 + 7038023 commit eb3aadc
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions contentcuration/contentcuration/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit eb3aadc

Please sign in to comment.