Skip to content

Commit

Permalink
Add limit to unassociate [RHELDST-20725]
Browse files Browse the repository at this point in the history
We want to perform garbage collection in batches to reduce the amount of
resources it consumes and avoid out of memory exceptions. Unit
association criteria have limit and skip fields which we could use for
batching requests.
  • Loading branch information
amcmahon-rh committed Oct 17, 2023
1 parent 6f26dd3 commit 0ebb6b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pubtools/pulplib/_impl/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ def _do_associate(self, src_repo_id, dest_repo_id, criteria=None, raw_options=No
self._do_request, method="POST", url=url, json=body
)

def _do_unassociate(self, repo_id, criteria=None):
def _do_unassociate(self, repo_id, criteria=None, limit=None, skip=None):
url = os.path.join(
self._url, "pulp/api/v2/repositories/%s/actions/unassociate/" % repo_id
)
Expand All @@ -800,6 +800,12 @@ def _do_unassociate(self, repo_id, criteria=None):
else:
body["criteria"]["filters"] = {"unit": pulp_search.filters}

if limit:
body["criteria"]["limit"] = limit

if skip:
body["criteria"]["skip"] = skip

LOG.debug("Submitting %s unassociate: %s", url, body)

return self._task_executor.submit(
Expand Down
9 changes: 8 additions & 1 deletion pubtools/pulplib/_impl/model/repository/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,14 @@ def remove_content(self, criteria=None, **kwargs):
Matcher.in_(type_ids), # Criteria.with_field_in is deprecated
)

return f_proxy(self._client._do_unassociate(self.id, criteria=criteria))
return f_proxy(
self._client._do_unassociate(
self.id,
criteria=criteria,
limit=kwargs.get("limit"),
skip=kwargs.get("skip"),
)
)

@classmethod
def from_data(cls, data):
Expand Down

0 comments on commit 0ebb6b6

Please sign in to comment.