Skip to content

Commit

Permalink
Merge pull request #53 from rigon/scanning-favorites
Browse files Browse the repository at this point in the history
FIX: not scanning album properly if has scanned for favorites
  • Loading branch information
rigon authored Oct 22, 2023
2 parents 5e07ca0 + 55cb8a0 commit 4fedc62
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
19 changes: 10 additions & 9 deletions server/album.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}

Expand Down
11 changes: 7 additions & 4 deletions server/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions server/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions server/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4fedc62

Please sign in to comment.