diff --git a/go.mod b/go.mod index 367f9b46..9f1b672b 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,12 @@ module github.com/ViBiOh/fibr go 1.19 require ( - github.com/ViBiOh/ChatPotte v0.2.11 + github.com/ViBiOh/ChatPotte v0.2.12 github.com/ViBiOh/absto v1.0.4 - github.com/ViBiOh/auth/v2 v2.14.7 + github.com/ViBiOh/auth/v2 v2.14.8 github.com/ViBiOh/exas v0.5.0 github.com/ViBiOh/flags v1.2.0 - github.com/ViBiOh/httputils/v4 v4.47.6 + github.com/ViBiOh/httputils/v4 v4.47.7 github.com/ViBiOh/vith v0.5.0 github.com/golang/mock v1.6.0 github.com/prometheus/client_golang v1.13.0 diff --git a/go.sum b/go.sum index b03c446b..f72367c1 100644 --- a/go.sum +++ b/go.sum @@ -33,18 +33,18 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/ViBiOh/ChatPotte v0.2.11 h1:zMJidUjpqUMhZCJpWsbm0Sagc+soEIC82dBqdpWFA3I= -github.com/ViBiOh/ChatPotte v0.2.11/go.mod h1:LbGXtNVr5OMaL8DGxmos56Pkm4gJY8Qg95dt0ilWIc8= +github.com/ViBiOh/ChatPotte v0.2.12 h1:yTfvwdIc4Z6W0tNguZdYDhQQ4m1p1nU0Bl1PAgWGDhc= +github.com/ViBiOh/ChatPotte v0.2.12/go.mod h1:3jZhDFjhP0nUoA+HIIVeXadnMT30qQfnr+vExeOFPi0= github.com/ViBiOh/absto v1.0.4 h1:j7GKLQzIyrCJUGU8Gvagse5wG5lLzJLNSSrMgVVDCnQ= github.com/ViBiOh/absto v1.0.4/go.mod h1:+e6RyntSHivIJ3FwVL8jefGVvYkDBS5gZ5XvdqXRtT0= -github.com/ViBiOh/auth/v2 v2.14.7 h1:ljZEutGnEqA3xVXfXW7J1PuCX+4lgxRpqAo2IO6GnGM= -github.com/ViBiOh/auth/v2 v2.14.7/go.mod h1:W24m80U3TLWlMr0Jy72BZY0vfpvZhFnnzl16TlRmQig= +github.com/ViBiOh/auth/v2 v2.14.8 h1:ix26s+ZF44wrMdhLHWa6ozVH4YFLBKqgIvTIuzTmj98= +github.com/ViBiOh/auth/v2 v2.14.8/go.mod h1:KrjZ/s3ZijLIW5RdIt9KndTxQU8d1EWNTYiV81o/Brg= github.com/ViBiOh/exas v0.5.0 h1:ZL5v5rUOkkwo6PxhbOVe96L0RUre7SfStaVcqhE/IbU= github.com/ViBiOh/exas v0.5.0/go.mod h1:sKRV/vz85Vj0caT+a3XWVFp0gyzXe36eZWL+XKge93E= github.com/ViBiOh/flags v1.2.0 h1:DaujjNXzD29KxKyp4eZdn7c9+uBN5DokWgDAe7DcUmc= github.com/ViBiOh/flags v1.2.0/go.mod h1:UyMB5zeD/aId7Xw3x7577ZNU298JmukzOcV8p/H2W1s= -github.com/ViBiOh/httputils/v4 v4.47.6 h1:T0no0RjRpvYv80dTfb9OnsKr0LXFu65p2bCqRfYKHgU= -github.com/ViBiOh/httputils/v4 v4.47.6/go.mod h1:qMX3opWLo3TBnjIOL4L/IOgObQf0gGsH0uF40sYydu8= +github.com/ViBiOh/httputils/v4 v4.47.7 h1:gClQ+LkLfbUFo0FgXKR4yhid69SgM1m+6n5MD8a/3uE= +github.com/ViBiOh/httputils/v4 v4.47.7/go.mod h1:qMX3opWLo3TBnjIOL4L/IOgObQf0gGsH0uF40sYydu8= github.com/ViBiOh/vith v0.5.0 h1:BpmjwWxd4NGmUJF12XpFOngK32539Lw3mvbMOaeOmhE= github.com/ViBiOh/vith v0.5.0/go.mod h1:Wf40eedOBEcxeLzGzGpuO+2G8qe5Ov1WIIBPXohyKco= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= diff --git a/pkg/exif/aggregate.go b/pkg/exif/aggregate.go index e9c6024c..18f27236 100644 --- a/pkg/exif/aggregate.go +++ b/pkg/exif/aggregate.go @@ -38,10 +38,7 @@ func (a App) ListExifFor(ctx context.Context, items ...absto.Item) (map[string]e ctx, end := tracer.StartSpan(ctx, a.tracer, "list_exif") defer end() - exifs, err := a.exifCacheApp.List(ctx, items...) - if err != nil { - return nil, err - } + exifs := a.exifCacheApp.List(ctx, onExifError, items...) output := make(map[string]exas.Exif, len(items)) exifsLen := len(exifs) @@ -70,10 +67,7 @@ func (a App) ListAggregateFor(ctx context.Context, items ...absto.Item) (map[str ctx, end := tracer.StartSpan(ctx, a.tracer, "list_aggregate") defer end() - exifs, err := a.aggregateCacheApp.List(ctx, items...) - if err != nil { - return nil, err - } + exifs := a.aggregateCacheApp.List(ctx, onAggregateError, items...) output := make(map[string]provider.Aggregate, len(items)) exifsLen := len(exifs) diff --git a/pkg/exif/error.go b/pkg/exif/error.go new file mode 100644 index 00000000..2b2830f9 --- /dev/null +++ b/pkg/exif/error.go @@ -0,0 +1,24 @@ +package exif + +import ( + "errors" + + absto "github.com/ViBiOh/absto/pkg/model" + "github.com/ViBiOh/httputils/v4/pkg/logger" +) + +func onExifError(item absto.Item, err error) bool { + if !absto.IsNotExist(err) && !errors.Is(err, errInvalidItemType) { + logger.WithField("item", item.Pathname).Error("load exif: %s", item.Pathname, err) + } + + return true +} + +func onAggregateError(item absto.Item, err error) bool { + if !absto.IsNotExist(err) && !errors.Is(err, errInvalidItemType) { + logger.WithField("item", item.Pathname).Error("load exif: %s", item.Pathname, err) + } + + return true +} diff --git a/pkg/exif/exif.go b/pkg/exif/exif.go index ae20e102..32bad225 100644 --- a/pkg/exif/exif.go +++ b/pkg/exif/exif.go @@ -110,12 +110,6 @@ func New(config Config, storageApp absto.Storage, prometheusRegisterer prometheu } return app.loadExif(ctx, item) - }, func(item absto.Item, err error) { - if absto.IsNotExist(err) || errors.Is(err, errInvalidItemType) { - return - } - - logger.WithField("item", item.Pathname).Error("load exif: %s", item.Pathname, err) }, cacheDuration, provider.MaxConcurrency, tracerApp.GetTracer("exif_cache")) app.aggregateCacheApp = cache.New(redisClient, redisKey, func(ctx context.Context, item absto.Item) (provider.Aggregate, error) { @@ -124,12 +118,6 @@ func New(config Config, storageApp absto.Storage, prometheusRegisterer prometheu } return app.loadAggregate(ctx, item) - }, func(item absto.Item, err error) { - if absto.IsNotExist(err) || errors.Is(err, errInvalidItemType) { - return - } - - logger.WithField("item", item.Pathname).Error("load exif: %s", item.Pathname, err) }, cacheDuration, provider.MaxConcurrency, tracerApp.GetTracer("ggregate_cache")) return app, nil diff --git a/pkg/thumbnail/error.go b/pkg/thumbnail/error.go new file mode 100644 index 00000000..e1c706d0 --- /dev/null +++ b/pkg/thumbnail/error.go @@ -0,0 +1,14 @@ +package thumbnail + +import ( + absto "github.com/ViBiOh/absto/pkg/model" + "github.com/ViBiOh/httputils/v4/pkg/logger" +) + +func onCacheError(pathname string, err error) bool { + if !absto.IsNotExist(err) { + logger.WithField("item", pathname).Error("get info: %s", pathname, err) + } + + return false +} diff --git a/pkg/thumbnail/thumbnail.go b/pkg/thumbnail/thumbnail.go index c9c9ad35..e49b7456 100644 --- a/pkg/thumbnail/thumbnail.go +++ b/pkg/thumbnail/thumbnail.go @@ -142,12 +142,6 @@ func New(config Config, storage absto.Storage, redisClient redis.App, prometheus app.cacheApp = cache.New(redisClient, redisKey, func(ctx context.Context, pathname string) (absto.Item, error) { return app.storageApp.Info(ctx, pathname) - }, func(pathname string, err error) { - if absto.IsNotExist(err) { - return - } - - logger.WithField("item", pathname).Error("get info: %s", pathname, err) }, redisCacheDuration, provider.MaxConcurrency, tracerApp.GetTracer("thumbnail_cache")) return app, nil @@ -265,14 +259,9 @@ func (a App) thumbnailHash(ctx context.Context, items []absto.Item) string { ids[index] = a.PathForScale(item, SmallSize) } - thumbnails, err := a.cacheApp.List(ctx, ids...) - if err != nil { - logger.Error("list thumbnail hash: %s", err) - } - hasher := sha.Stream() - for _, thumbnail := range thumbnails { + for _, thumbnail := range a.cacheApp.List(ctx, onCacheError, ids...) { hasher.Write(thumbnail) } diff --git a/pkg/thumbnail/utils_test.go b/pkg/thumbnail/utils_test.go index 51a0d3a1..285f4705 100644 --- a/pkg/thumbnail/utils_test.go +++ b/pkg/thumbnail/utils_test.go @@ -87,7 +87,7 @@ func TestHasThumbnail(t *testing.T) { storageMock := mocks.NewStorage(ctrl) tc.instance.storageApp = storageMock - tc.instance.cacheApp = cache.New(nil, nil, storageMock.Info, nil, 0, 0, nil) + tc.instance.cacheApp = cache.New(nil, nil, storageMock.Info, 0, 0, nil) if intention == "found" { storageMock.EXPECT().Info(gomock.Any(), gomock.Any()).Return(absto.Item{}, nil)