From 55cb8a0eaf4dc8fb7ad891349b49385c56a5d525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gon=C3=A7alves?= Date: Sun, 22 Oct 2023 10:22:12 +0000 Subject: [PATCH] FIX: not scanning album properly if has scanned for favorites --- server/album.go | 19 ++++++++++--------- server/cache.go | 11 +++++++---- server/collection.go | 4 ++++ server/scan.go | 4 ++-- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/server/album.go b/server/album.go index 23a12b7..dd1e9c8 100644 --- a/server/album.go +++ b/server/album.go @@ -29,6 +29,13 @@ func (album *Album) GetPhotos(collection *Collection, runningInBackground bool, subAlbums := make(map[string]bool) album.photosMap = make(map[string]*Photo) + // Convert photosToLoad to a map for improved performance + photosToLoadMap := make(map[string]bool) + for _, entry := range photosToLoad { + key := entry.Collection + ":" + entry.Album + ":" + entry.Photo + photosToLoadMap[key] = true + } + if album.IsPseudo { // Read pseudo album log.Printf("Scanning pseudo-album %s[%s]...", collection.Name, album.Name) @@ -68,15 +75,9 @@ func (album *Album) GetPhotos(collection *Collection, runningInBackground bool, // Load only the selected photos if len(photosToLoad) > 0 { - found := false - for _, entry := range photosToLoad { - if entry.Collection == collection.Name && entry.Album == album.Name && entry.Photo == fileId { - found = true - break - } - } - if !found { // if not in the list, skip - return nil + keyToFind := collection.Name + ":" + album.Name + ":" + fileId + if _, found := photosToLoadMap[keyToFind]; !found { + return nil // Entry not found in the map, skip } } diff --git a/server/cache.go b/server/cache.go index 6df8a7f..833645f 100644 --- a/server/cache.go +++ b/server/cache.go @@ -137,14 +137,17 @@ func (c *Cache) GetAlbum(albumName string) (*Album, error) { } func (c *Cache) SaveAlbum(album *Album) error { - // Flag this album as loaded - type AlbumSaved struct{} - go c.store.Upsert(album.Name, AlbumSaved{}) // Cache album in memory return c.mem.Set(album.Name, album) } -func (c *Cache) WasAlbumSaved(album *Album) bool { +func (c *Cache) SetAlbumFullyScanned(album *Album) error { + // Flag this album as loaded + type AlbumSaved struct{} + return c.store.Upsert(album.Name, AlbumSaved{}) +} + +func (c *Cache) IsAlbumFullyScanned(album *Album) bool { type AlbumSaved struct{} var a AlbumSaved return c.store.Get(album.Name, &a) == nil diff --git a/server/collection.go b/server/collection.go index 5cee581..59cb19f 100644 --- a/server/collection.go +++ b/server/collection.go @@ -186,6 +186,10 @@ func (c *Collection) GetAlbumWithPhotos(albumName string, forceUpdate bool, runn album.GetPhotos(c, runningInBackground, photosToLoad...) // ...and save to cache c.cache.SaveAlbum(album) + // Set album as fully scanned + if len(photosToLoad) < 1 { // only when partial load is not performed + c.cache.SetAlbumFullyScanned(album) + } return album, nil } diff --git a/server/scan.go b/server/scan.go index 58974a9..ded1b52 100644 --- a/server/scan.go +++ b/server/scan.go @@ -20,8 +20,8 @@ func (collection *Collection) Scan(fullScan bool) error { // Quick scan if !fullScan { for _, album := range albums { - if !collection.cache.WasAlbumSaved(album) { // Skip album if it was already scanned - collection.GetAlbumWithPhotos(album.Name, false, true) + if !collection.cache.IsAlbumFullyScanned(album) { // Skip album if it was already scanned + collection.GetAlbumWithPhotos(album.Name, true, true) } } return nil