From 2ca285dd5bccfee05940ddda4275c7328b97abc3 Mon Sep 17 00:00:00 2001 From: Vincent Boutour Date: Sat, 3 Sep 2022 13:06:55 +0200 Subject: [PATCH] refactor: using listing for thumbnail etag Signed-off-by: Vincent Boutour --- pkg/thumbnail/thumbnail.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/thumbnail/thumbnail.go b/pkg/thumbnail/thumbnail.go index b5cff95e..5d149c58 100644 --- a/pkg/thumbnail/thumbnail.go +++ b/pkg/thumbnail/thumbnail.go @@ -251,12 +251,20 @@ func (a App) List(w http.ResponseWriter, r *http.Request, item absto.Item, items } func (a App) thumbnailHash(ctx context.Context, items []absto.Item) string { + ids := make([]string, len(items)) + for index, item := range items { + ids[index] = a.PathForScale(item, SmallSize) + } + + thumbnails, err := a.cacheApp.List(ctx, 10, ids...) + if err != nil { + logger.Error("list thumbnail hash: %s", err) + } + hasher := sha.Stream() - for _, item := range items { - if info, err := a.Info(ctx, a.PathForScale(item, SmallSize)); err == nil { - hasher.Write(info) - } + for _, thumbnail := range thumbnails { + hasher.Write(thumbnail) } return hasher.Sum()