From a6f60ad39f6df9cacea9ab49d4e425333ab96b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Mon, 13 Mar 2023 10:34:57 +0100 Subject: [PATCH] Switch msgpack library to a faster, leaner one --- go.mod | 3 +-- go.sum | 6 ++---- pkg/storage/cache/cache.go | 11 +++-------- .../decomposedfs/metadata/messagepack_backend.go | 6 +++++- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 4d7da32f80..60fdc5b49e 100644 --- a/go.mod +++ b/go.mod @@ -64,6 +64,7 @@ require ( github.com/rs/zerolog v1.28.0 github.com/sciencemesh/meshdirectory-web v1.0.4 github.com/sethvargo/go-password v0.2.0 + github.com/shamaton/msgpack/v2 v2.1.1 github.com/stretchr/testify v1.8.1 github.com/studio-b12/gowebdav v0.0.0-20221015232716-17255f2e7423 github.com/test-go/testify v1.1.4 @@ -189,8 +190,6 @@ require ( github.com/stretchr/objx v0.5.0 // indirect github.com/tidwall/pretty v1.2.1 // indirect github.com/urfave/cli/v2 v2.20.3 // indirect - github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect - github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/xanzy/ssh-agent v0.3.2 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect go.etcd.io/etcd/api/v3 v3.5.5 // indirect diff --git a/go.sum b/go.sum index 5aa60c0b92..9de019ff69 100644 --- a/go.sum +++ b/go.sum @@ -853,6 +853,8 @@ github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNX github.com/sethgrid/pester v0.0.0-20190127155807-68a33a018ad0/go.mod h1:Ad7IjTpvzZO8Fl0vh9AzQ+j/jYZfyp2diGwI8m5q+ns= github.com/sethvargo/go-password v0.2.0 h1:BTDl4CC/gjf/axHMaDQtw507ogrXLci6XRiLc7i/UHI= github.com/sethvargo/go-password v0.2.0/go.mod h1:Ym4Mr9JXLBycr02MFuVQ/0JHidNetSgbzutTr3zsYXE= +github.com/shamaton/msgpack/v2 v2.1.1 h1:gAMxOtVJz93R0EwewwUc8tx30n34aV6BzJuwHE8ogAk= +github.com/shamaton/msgpack/v2 v2.1.1/go.mod h1:aTUEmh31ziGX1Ml7wMPLVY0f4vT3CRsCvZRoSCs+VGg= github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk= github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg= github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 h1:pXY9qYc/MP5zdvqWEUH6SjNiu7VhSjuVFTFiTcphaLU= @@ -904,10 +906,6 @@ github.com/urfave/cli/v2 v2.20.3 h1:lOgGidH/N5loaigd9HjFsOIhXSTrzl7tBpHswZ428w4= github.com/urfave/cli/v2 v2.20.3/go.mod h1:1CNUng3PtjQMtRzJO4FMXBQvkGtuYRxxiR9xMa7jMwI= github.com/vimeo/go-util v1.2.0/go.mod h1:s13SMDTSO7AjH1nbgp707mfN5JFIWUFDU5MDDuRRtKs= github.com/vimeo/go-util v1.4.1/go.mod h1:r+yspV//C48HeMXV8nEvtUeNiIiGfVv3bbEHzOgudwE= -github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU= -github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= -github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= -github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= github.com/wk8/go-ordered-map v1.0.0 h1:BV7z+2PaK8LTSd/mWgY12HyMAo5CEgkHqbkVq2thqr8= github.com/wk8/go-ordered-map v1.0.0/go.mod h1:9ZIbRunKbuvfPKyBP1SIKLcXNlv74YCOZ3t3VTS6gRk= github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0= diff --git a/pkg/storage/cache/cache.go b/pkg/storage/cache/cache.go index 0f1f507897..98896ad7f0 100644 --- a/pkg/storage/cache/cache.go +++ b/pkg/storage/cache/cache.go @@ -19,7 +19,6 @@ package cache import ( - "bytes" "fmt" "strings" "sync" @@ -32,7 +31,7 @@ import ( redisopts "github.com/go-redis/redis/v8" "github.com/nats-io/nats.go" microetcd "github.com/owncloud/ocis/v2/ocis-pkg/store/etcd" - msgpack "github.com/vmihailenco/msgpack/v5" + "github.com/shamaton/msgpack/v2" microstore "go-micro.dev/v4/store" ) @@ -240,12 +239,8 @@ func (cache cacheStore) PullFromCache(key string, dest interface{}) error { if len(r) == 0 { return fmt.Errorf("not found") } - // we seem to need the TypedMap decoder: https://github.com/vmihailenco/msgpack/issues/327 - decoder := msgpack.NewDecoder(bytes.NewReader(r[0].Value)) - decoder.SetMapDecoder(func(dec *msgpack.Decoder) (interface{}, error) { - return dec.DecodeTypedMap() - }) - return decoder.Decode(&dest) + + return msgpack.Unmarshal(r[0].Value, &dest) } // PushToCache pushes a key and value to the configured database and table of the underlying store diff --git a/pkg/storage/utils/decomposedfs/metadata/messagepack_backend.go b/pkg/storage/utils/decomposedfs/metadata/messagepack_backend.go index abe108a2a0..9d13cdab33 100644 --- a/pkg/storage/utils/decomposedfs/metadata/messagepack_backend.go +++ b/pkg/storage/utils/decomposedfs/metadata/messagepack_backend.go @@ -176,7 +176,11 @@ func (b MessagePackBackend) saveAttributes(path string, setAttribs map[string][] } // Write new metadata to file - msgpack.NewEncoder(f).Encode(attribs) + d, err := msgpack.Marshal(attribs) + if err != nil { + return err + } + _, err = f.Write(d) if err != nil { return err }