1717from collections import defaultdict
1818
1919from pulp_ansible .app .models import Collection , CollectionVersion
20- from pulp_ansible .app .utils import set_collection_deferred_fields
2120from pulpcore .plugin .tasking import add_and_remove , orphan_cleanup
2221
2322log = logging .getLogger (__name__ )
@@ -33,7 +32,7 @@ def _remove_collection_version_from_repos(collection_versions):
3332 """Remove CollectionVersions from latest RepositoryVersion of each repo."""
3433 repos_with_collections_to_delete = defaultdict (list )
3534 for collection_version in collection_versions :
36- for repo in collection_version .repositories .all ( ):
35+ for repo in collection_version .repositories .only ( "pk" ):
3736 repos_with_collections_to_delete [repo ].append (collection_version .pk )
3837 for repo , collections in repos_with_collections_to_delete .items ():
3938 add_and_remove (repo .pk , add_content_units = [], remove_content_units = collections )
@@ -72,11 +71,8 @@ def delete_collection(collection_pk):
7271 2. Run orphan_cleanup to delete the CollectionVersions
7372 3. Delete Collection
7473 """
75- # Defer loading large JSON fields to prevent memory exhaustion
76- set_collection_deferred_fields (["contents" , "docs_blob" , "manifest" , "files" , "dependencies" ])
77-
7874 collection = Collection .objects .get (pk = collection_pk )
79- versions = collection .versions .all ( )
75+ versions = collection .versions .only ( "pk" )
8076 _remove_collection_version_from_repos (versions )
8177 version_pks = versions .values_list ("pk" , flat = True )
8278
0 commit comments