Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize garabge collection command #4808

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading