Albums: Improve performance when setting/refreshing cover images #5253

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer
2025-10-10 17:51:55 +02:00
parent 92d21af697
commit c5d17c579c
4 changed files with 362 additions and 25 deletions

View File

@@ -9,8 +9,10 @@ import (
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/entity/query"
"github.com/photoprism/photoprism/internal/photoprism/get"
"github.com/photoprism/photoprism/internal/thumb"
"github.com/photoprism/photoprism/pkg/fs"
@@ -56,7 +58,12 @@ func TestRemoveFromAlbumCoverCache(t *testing.T) {
cache := get.CoverCache()
cache.Flush()
uid := rnd.GenerateUID(entity.AlbumUID)
var album entity.Album
if err := query.UnscopedDb().Where("album_type = ? AND thumb_src = ?", entity.AlbumManual, entity.SrcAuto).First(&album).Error; err != nil {
t.Skipf("no auto-managed manual album available: %v", err)
}
uid := album.AlbumUID
for thumbName := range thumb.Sizes {
key := CacheKey(albumCover, uid, string(thumbName))
@@ -76,6 +83,15 @@ func TestRemoveFromAlbumCoverCache(t *testing.T) {
t.Fatalf("write %s: %v", sharePreview, err)
}
origThumb := album.Thumb
origThumbSrc := album.ThumbSrc
t.Cleanup(func() {
_ = entity.UpdateAlbum(uid, entity.Values{"thumb": origThumb, "thumb_src": origThumbSrc})
})
require.NoError(t, entity.UpdateAlbum(uid, entity.Values{"thumb": "", "thumb_src": entity.SrcAuto}))
RemoveFromAlbumCoverCache(uid)
for thumbName := range thumb.Sizes {
@@ -86,6 +102,12 @@ func TestRemoveFromAlbumCoverCache(t *testing.T) {
_, err := os.Stat(sharePreview)
assert.True(t, os.IsNotExist(err))
entity.FlushAlbumCache()
refreshed, err := query.AlbumByUID(uid)
require.NoError(t, err)
assert.NotEmpty(t, refreshed.Thumb)
}
func TestRemoveFromAlbumCoverCacheInvalidUID(t *testing.T) {