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

feat(storage): add arguments for *GenerationMatch uploading options #111

Merged
merged 7 commits into from Apr 22, 2020

Conversation

@IlyaFaer
Copy link
Member

@IlyaFaer IlyaFaer commented Apr 21, 2020

These changes were originally made in another PR. Here is the version with changes requested by reviews.
Closes #16

@frankyn frankyn requested review from crwilcox, tseaver and frankyn and removed request for tseaver Apr 21, 2020
@IlyaFaer IlyaFaer marked this pull request as ready for review Apr 21, 2020
Copy link
Member

@frankyn frankyn left a comment

Documentation nit.

google/cloud/storage/blob.py Outdated Show resolved Hide resolved
Copy link
Member

@frankyn frankyn left a comment

LGTM, ty!

@frankyn frankyn merged commit b11aa5f into googleapis:master Apr 22, 2020
3 checks passed
@IlyaFaer IlyaFaer deleted the if_generation_match branch Apr 23, 2020
@1fish2
Copy link

@1fish2 1fish2 commented Apr 27, 2020

👍 Thanks to @HollayHorvath and @frankyn!

The code to create a directory placeholder changes from

blob = bucket.blob(name)
if not blob.exists():
    blob.upload_from_string(b'', content_type=OCTET_STREAM)

to

blob = bucket.blob(name)
try:
    blob.upload_from_string(
        b'', content_type=OCTET_STREAM, if_generation_match=0)
except PreconditionFailed:
    pass

because, as the doc says, "Setting to 0 makes the operation succeed only if there are no live versions of the blob."

In a handful of timings, the new code saved more than half the didn't-exist time and a bit of the already-exists time (although that might be measurement noise).

cojenco added a commit to cojenco/python-storage that referenced this issue Oct 13, 2021
…oogleapis#111)

* feat(storage): add arguments for *GenerationMatch uploading options

* add unit tests changes

* change args names in unit tests

* add unit tests for _do_multipart_upload()

* add unit tests for _initiate_resumable_upload()

* add args translation into unit tests urls

* update args docs
cojenco added a commit to cojenco/python-storage that referenced this issue Oct 13, 2021
…oogleapis#111)

* feat(storage): add arguments for *GenerationMatch uploading options

* add unit tests changes

* change args names in unit tests

* add unit tests for _do_multipart_upload()

* add unit tests for _initiate_resumable_upload()

* add args translation into unit tests urls

* update args docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants