Skip to content

Commit

Permalink
Merge pull request #954 from ATIX-AG/use_pulpcore_batch_qs
Browse files Browse the repository at this point in the history
Use pulpcore batch qs
  • Loading branch information
hstct authored Nov 20, 2023
2 parents 3a87265 + 3de2554 commit 1e55c5a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
25 changes: 3 additions & 22 deletions pulp_deb/app/models/repository.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django.db import models
from pulpcore.plugin.models import BaseModel, Repository

from pulpcore.plugin.models import BaseModel, Content, Repository
from pulpcore.plugin.repo_version_utils import (
remove_duplicates,
validate_version_paths,
validate_duplicate_content,
)

from pulpcore.plugin.models import Content
from pulpcore.plugin.util import batch_qs

from pulp_deb.app.models import (
AptReleaseSigningService,
Expand Down Expand Up @@ -195,22 +195,3 @@ def handle_duplicate_packages(new_version):
log.warning(message.format(pulp_type))
new_version.remove_content(package_qs_duplicates)
new_version.remove_content(prc_qs_duplicates)


# The following helper function is copy and pasted from pulpcore. As soon as
# https://github.com/pulp/pulpcore/issues/4607 is ready, we should replace it with an import!
def batch_qs(qs, batch_size=1000):
"""
Returns a queryset batch in the given queryset.
Usage:
# Make sure to order your querset
article_qs = Article.objects.order_by('id')
for qs in batch_qs(article_qs):
for article in qs:
print article.body
"""
total = qs.count()
for start in range(0, total, batch_size):
end = min(start + batch_size, total)
yield qs[start:end]
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# All things django and asyncio are deliberately left to pulpcore
# Example transitive requirements: asgiref, asyncio, aiohttp
pulpcore>=3.40.1,<3.55
pulpcore>=3.41.0,<3.55
python-debian>=0.1.44,<0.2.0
python-gnupg>=0.5,<0.6
jsonschema>=4.6,<5.0

0 comments on commit 1e55c5a

Please sign in to comment.