Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR #309/0e193194 backport][2.2] Use a customized version of QueryExistingArtifacts #314

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/289.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved the performance of subsequent imports.
41 changes: 39 additions & 2 deletions pulp_ostree/app/tasks/importing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
ArtifactSaver,
ContentSaver,
DeclarativeVersion,
QueryExistingArtifacts,
QueryExistingContents,
ResolveContentFutures,
Stage,
)
from pulpcore.plugin.sync import sync_to_async_iterable

from pulp_ostree.app.models import (
OstreeCommit,
Expand Down Expand Up @@ -371,14 +371,51 @@ async def run(self):
await self.submit_metafile_object("summary", OstreeSummary())


class QueryExistingArtifactsOstree(Stage):
"""A customized version of the QueryExistingArtifacts stage comparing just sha256 digests."""

async def run(self):
"""Compare existing artifacts by leveraging dictionary access."""
async for batch in self.batches():
artifacts_digests = []

for d_content in batch:
d_artifact = d_content.d_artifacts[0]
if d_artifact.artifact._state.adding:
digest_value = d_artifact.artifact.sha256
artifacts_digests.append(digest_value)

query_params = {
"sha256__in": artifacts_digests,
"pulp_domain": self.domain,
}

existing_artifacts_qs = Artifact.objects.filter(**query_params)
await sync_to_async(existing_artifacts_qs.touch)()

d = {}
async for result in sync_to_async_iterable(existing_artifacts_qs):
d[result.sha256] = result

for d_content in batch:
d_artifact = d_content.d_artifacts[0]
artifact_digest = d_artifact.artifact.sha256
m = d.get(artifact_digest)
if m:
d_artifact.artifact = m

for d_content in batch:
await self.put(d_content)


class OstreeImportDeclarativeVersion(DeclarativeVersion):
"""A customized DeclarativeVersion class that creates a pipeline for the OSTree import."""

def pipeline_stages(self, new_version):
"""Build a list of stages."""
pipeline = [
self.first_stage,
QueryExistingArtifacts(),
QueryExistingArtifactsOstree(),
ArtifactSaver(),
QueryExistingContents(),
ContentSaver(),
Expand Down
Loading