-
Notifications
You must be signed in to change notification settings - Fork 45
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
Verify if a manifest already exists locally when syncing a remote repo. #1133
Conversation
2e618b6
to
47476d6
Compare
94e8c78
to
e3002da
Compare
e3002da
to
fa44324
Compare
digest = dl_res.artifact_attributes["sha256"] | ||
validate_manifest(content_data, media_type, digest) | ||
for artifact in asyncio.as_completed(to_download_artifact): | ||
saved_artifact, content_data, raw_data, response = await artifact |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider returning here just raw_data and on the line after do json.load for the content_data
response.artifact_attributes["file"] = response.path | ||
|
||
saved_artifact = await sync_to_async(_save_artifact_blocking)(response.artifact_attributes) | ||
content_data = json.loads(raw_data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure, you probably don't need to return content_data here. just raw_data should suffice
raw_data = saved_artifact.file | ||
content_data = json.load(raw_data) | ||
saved_artifact.file.close() | ||
return saved_artifact, content_data, raw_data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about we return just just raw_data and later on where it is needed we can json.load it. I am trying to avoid to carry both content_data and raw_data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it, but there are some places where I need to use _get_content_data_blocking
and _download_and_save_artifact_data
. Specially in the create_listed_manifest
, where there are statements under the else
branch that need content_data
. I will end calling json.load more times than if left where they are now. 😭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am also in favour of removing content_data
from the return parameters. You will call json.load
two times instead of one. Or not? Still, the number of parameters will decrease all around the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will be written in the code twice - under if and under else branch but in the end of the day called it will be once.
fa44324
to
e2e8b13
Compare
d5b525a
to
f860076
Compare
d21e24c
to
a029df5
Compare
saved_artifact = manifest.contentartifact_set.first().artifact | ||
raw_data = saved_artifact.file.read() | ||
content_data = json.loads(raw_data) | ||
saved_artifact.file.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use context manager here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good thank you! We can look into how optimize on the returned parameters in the follow up PR.
a029df5
to
709f27b
Compare
Closes #1047