Skip to content

Commit 5d0a328

Browse files
committed
FIX: collision with ids in cache
1 parent 8ecf472 commit 5d0a328

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

server/cache.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,22 @@ func (c Cache) FillPhotosInfo(album *Album) (err error) {
122122

123123
// Get photos that are in cache
124124
err = c.store.Bolt().View(func(tx *bolt.Tx) error {
125+
size := len(album.photosMap)
126+
count := 0
125127
for _, photo := range album.photosMap {
126128
var data Photo
127-
key := album.Name + ":" + photo.Title
129+
count++
130+
key := album.Name + ":" + photo.Id
128131
err := c.store.TxGet(tx, key, &data)
129132
// Does not require update
130-
if err == nil && data.Title == photo.Title && data.Thumb == photo.Thumb &&
133+
if err == nil && data.Id == photo.Id && data.Thumb == photo.Thumb &&
131134
len(data.Files) == len(photo.Files) { // Validate some fields
132135

133136
*photo = data
134137
continue
135138
}
136139

137-
log.Printf("caching photo [%s] %s", album.Name, photo.Title)
140+
log.Printf("Caching photo info [%s] %d/%d: %s %s\n", album.Name, count, size, photo.Title, photo.SubAlbum)
138141
photo.FillInfo()
139142
update = append(update, photo)
140143
}
@@ -149,7 +152,7 @@ func (c Cache) FillPhotosInfo(album *Album) (err error) {
149152
// Update missing entries
150153
return c.store.Bolt().Update(func(tx *bolt.Tx) error {
151154
for _, photo := range update {
152-
key := album.Name + ":" + photo.Title
155+
key := album.Name + ":" + photo.Id
153156
err := c.store.TxUpsert(tx, key, photo)
154157
if err != nil {
155158
log.Println(err)

server/photo.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ func (photo *Photo) GetThumbnail(collection *Collection, album *Album, w io.Writ
7878
if selected == nil {
7979
return errors.New("is not a photo")
8080
}
81-
log.Printf("Creating thumbnail for [%s] %s", album.Name, photo.Title)
8281
err := selected.CreateThumbnail(thumbPath, w)
8382
if err != nil {
8483
err := fmt.Errorf("failed to creating thumbnail for [%s] %s: %v", album.Name, photo.Title, err)

server/worker.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ func AddWorkPhoto(collection *Collection, album *Album, photo *Photo, writer io.
4747
}
4848

4949
func AddWorkPhotos(collection *Collection, album *Album) {
50+
size := len(album.photosMap)
51+
count := 0
5052
for _, photo := range album.photosMap {
51-
log.Printf("Background Thumb [%s] %s\n", album.Name, photo.Title)
53+
count++
54+
log.Printf("Background thumbnail %s[%s] %d/%d: %s %s\n", collection.Name, album.Name, count, size, photo.Title, photo.SubAlbum)
5255
wg.Add(1)
5356
w := new(Work)
5457
w.collection = collection

0 commit comments

Comments
 (0)