From 6237dc1383990df023bc5e2510c40cbd25dce5bf Mon Sep 17 00:00:00 2001 From: Babis Kiosidis Date: Thu, 14 Jul 2022 13:57:46 +0300 Subject: [PATCH] combine write and update to one request Signed-off-by: Babis Kiosidis --- google/container.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/google/container.go b/google/container.go index 04daa48..07fbcb1 100644 --- a/google/container.go +++ b/google/container.go @@ -114,17 +114,25 @@ func (c *Container) Put(name string, r io.Reader, size int64, metadata map[strin } w := obj.NewWriter(c.ctx) + w.ObjectAttrs.Metadata = merge(w.ObjectAttrs.Metadata, mdPrepped) if _, err := io.Copy(w, r); err != nil { return nil, err } - w.Close() - - attr, err := obj.Update(c.ctx, storage.ObjectAttrsToUpdate{Metadata: mdPrepped}) - if err != nil { + if err = w.Close(); err != nil { return nil, err } - return c.convertToStowItem(attr) + return c.convertToStowItem(w.Attrs()) +} + +func merge(metadata ...map[string]string) map[string]string { + res := map[string]string{} + for _, mt := range metadata { + for k, v := range mt { + res[k] = v + } + } + return res } func (c *Container) convertToStowItem(attr *storage.ObjectAttrs) (stow.Item, error) {