Skip to content

Commit 4086830

Browse files
committed
Updating collection delete functions to use the same memory saving measures as sync
1 parent c5bb21e commit 4086830

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reduced memory usage when deleting collections with many versions.

pulp_ansible/app/galaxy/v3/views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080

8181
from pulp_ansible.app.tasks.deletion import delete_collection_version, delete_collection
8282

83-
from pulp_ansible.app.utils import filter_content_for_repo_version
83+
from pulp_ansible.app.utils import filter_content_for_repo_version, set_collection_deferred_fields
8484

8585
DOMAIN_ENABLED = settings.DOMAIN_ENABLED
8686

@@ -446,6 +446,9 @@ def destroy(self, request: Request, *args, **kwargs) -> Response:
446446
status=status.HTTP_400_BAD_REQUEST,
447447
)
448448

449+
# Defer loading large JSON fields to prevent memory exhaustion when deleting collections with many versions
450+
set_collection_deferred_fields(['contents', 'docs_blob', 'manifest', 'files', 'dependencies'])
451+
449452
repositories = set()
450453
for version in collection.versions.all():
451454
for repo in version.repositories.all():

pulp_ansible/app/tasks/deletion.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from collections import defaultdict
1818

1919
from pulp_ansible.app.models import Collection, CollectionVersion
20+
from pulp_ansible.app.utils import set_collection_deferred_fields
2021
from pulpcore.plugin.tasking import add_and_remove, orphan_cleanup
2122

2223
log = logging.getLogger(__name__)
@@ -71,6 +72,9 @@ def delete_collection(collection_pk):
7172
2. Run orphan_cleanup to delete the CollectionVersions
7273
3. Delete Collection
7374
"""
75+
# Defer loading large JSON fields to prevent memory exhaustion when deleting collections with many versions
76+
set_collection_deferred_fields(['contents', 'docs_blob', 'manifest', 'files', 'dependencies'])
77+
7478
collection = Collection.objects.get(pk=collection_pk)
7579
versions = collection.versions.all()
7680
_remove_collection_version_from_repos(versions)

0 commit comments

Comments
 (0)