From c148adb225f1676bf464a7d483d5876175813f2e Mon Sep 17 00:00:00 2001 From: Louis Dalibard Date: Mon, 10 Jun 2024 22:25:05 +0200 Subject: [PATCH] fix: while waiting some other thread could have generated the thumbnail --- thumbnail/thumbnail.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/thumbnail/thumbnail.go b/thumbnail/thumbnail.go index b5e5379..d5203c1 100644 --- a/thumbnail/thumbnail.go +++ b/thumbnail/thumbnail.go @@ -72,6 +72,14 @@ func GetThumbnail(c *fiber.Ctx, completePath string) { return } WaitForAvailable() + /* While waiting some other thread could have generated the thumbnail */ + thumbnailCacheMutex.RLock() + bytesThumb, ok = thumbnailCache[completePath] + thumbnailCacheMutex.RUnlock() + if ok { + c.Write(bytesThumb) + return + } fileExt := filepath.Ext(completePath) if !slices.Contains(SupportedFileTypes, fileExt) {