diff options
| author | Dan Engelbrecht <[email protected]> | 2023-08-09 10:38:01 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-08-09 10:38:01 +0200 |
| commit | 5d8979b00ef10728679bc3fadf3708afec319806 (patch) | |
| tree | 5fe1862279cab0a0505498bdaef1803d11398a64 | |
| parent | Bugfix: `oplog-import` with `--file` source now sends the oplog folder correc... (diff) | |
| download | zen-5d8979b00ef10728679bc3fadf3708afec319806.tar.xz zen-5d8979b00ef10728679bc3fadf3708afec319806.zip | |
use streaming read for PutCompressedBlob if source is single file (#338)
* use streaming read for PutCompressedBlob if source is single file
* changelog
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | src/zenserver/upstream/jupiter.cpp | 19 |
2 files changed, 19 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 4445bf9cd..35164d10d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Improvement: Keep reason and status code when parsing responses from jupiter remote requests - Improvement: Add additional context for errors when importing/exporting oplogs - Improvement: Added `ZenServerInstance::SpawnServerAndWait` and improved logic around process termination when using `ZenServerInstance::AttachToRunningServer` +- Improvement: When uploading compressed blob to jupiter, use streaming reading of source file if it is a "whole file" - a large attachment. ## 0.2.13 - Feature: Project store now has a `snapshot` RPC on oplogs which may be used to inline any files referenced by name into Zen store. This makes the oplog transportable diff --git a/src/zenserver/upstream/jupiter.cpp b/src/zenserver/upstream/jupiter.cpp index 32537508c..e7bb2cbcf 100644 --- a/src/zenserver/upstream/jupiter.cpp +++ b/src/zenserver/upstream/jupiter.cpp @@ -445,7 +445,24 @@ CloudCacheSession::PutCompressedBlob(std::string_view Namespace, const IoHash& K Session.SetOption(cpr::Url{Uri.c_str()}); Session.SetOption(cpr::Header{{"Authorization", AccessToken.Value}, {"Content-Type", "application/x-ue-comp"}}); - Session.SetBody(cpr::Body{(const char*)Blob.Data(), Blob.Size()}); + + uint64_t Offset = 0; + if (Blob.IsWholeFile()) + { + auto ReadCallback = [&Blob, &Offset](char* buffer, size_t& size, intptr_t) { + size = Min<size_t>(size, Blob.GetSize() - Offset); + IoBuffer PayloadRange = IoBuffer(Blob, Offset, size); + MutableMemoryView Data(buffer, size); + Data.CopyFrom(PayloadRange.GetView()); + Offset += size; + return true; + }; + Session.SetReadCallback(cpr::ReadCallback(gsl::narrow<cpr::cpr_off_t>(Blob.GetSize()), ReadCallback)); + } + else + { + Session.SetBody(cpr::Body{(const char*)Blob.Data(), Blob.Size()}); + } cpr::Response Response = Session.Put(); ZEN_DEBUG("PUT {}", Response); |