From cc338d2039010b844e66e5b3fd3327ef63fb637b Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Fri, 30 Jul 2021 18:25:53 +0200 Subject: [PATCH] Add touch to QuerySets of artifacts or content fixes #9234 --- CHANGES/plugin_api/9234.feature | 1 + pulpcore/app/models/content.py | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 CHANGES/plugin_api/9234.feature diff --git a/CHANGES/plugin_api/9234.feature b/CHANGES/plugin_api/9234.feature new file mode 100644 index 0000000000..cab78cd4a5 --- /dev/null +++ b/CHANGES/plugin_api/9234.feature @@ -0,0 +1 @@ +Added ``touch`` to Artifact and Content query sets for bulk operation. diff --git a/pulpcore/app/models/content.py b/pulpcore/app/models/content.py index 83bfc460de..921f4c026c 100644 --- a/pulpcore/app/models/content.py +++ b/pulpcore/app/models/content.py @@ -92,6 +92,18 @@ def bulk_get_or_create(self, objs, batch_size=None): return objs +class BulkTouchQuerySet(models.QuerySet): + """ + A query set that provides ``touch()``. + """ + + def touch(self): + """ + Update the ``timestamp_of_interest`` on all objects of the query. + """ + return self.update(timestamp_of_interest=now()) + + class QueryMixin: """ A mixin that provides models with querying utilities. @@ -192,7 +204,7 @@ def storage_path(self, name): sha512 = models.CharField(max_length=128, null=True, unique=True, db_index=True) timestamp_of_interest = models.DateTimeField(auto_now=True) - objects = ArtifactManager() + objects = ArtifactManager.from_queryset(BulkTouchQuerySet)() # All available digest fields ordered by algorithm strength. DIGEST_FIELDS = _DIGEST_FIELDS @@ -470,7 +482,7 @@ class Content(MasterModel, QueryMixin): _artifacts = models.ManyToManyField(Artifact, through="ContentArtifact") timestamp_of_interest = models.DateTimeField(auto_now=True) - objects = ContentManager() + objects = ContentManager.from_queryset(BulkTouchQuerySet)() class Meta: verbose_name_plural = "content"