mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-17 07:38:46 +01:00
fix(artwork): give full-size disc art a real ETag
Regression from 04d5a556. Keying the resize cache on identity meant the
disc response no longer carried a content hash, and the full-size branch
set no ETag either — so WriteImageHeaders fell back to the empty hash
and emitted `ETag: ""` for every full-size disc image. Since ifNoneMatch
compares the unquoted value, a client echoing that back matched, and got
a 304 even after the image was replaced.
The full-size branch now carries the same identity validator the sized
branch uses, so it moves when the folder's images change.
WriteImageHeaders is hardened against the class as well: an empty
validator is no validator, so it is neither emitted nor matched.
Reported by Codex on #5847.
This commit is contained in:
parent
f4dd71d06e
commit
6bb3e98e4c
4 changed files with 48 additions and 10 deletions
|
|
@ -313,20 +313,19 @@ func (s *service) serveDisc(ctx context.Context, artID model.ArtworkID, size int
|
|||
return selectImageReader(ctx, artID, funcs...)
|
||||
}
|
||||
albumArtID := model.ArtworkID{Kind: model.KindAlbumArtwork, ID: dr.album.ID}
|
||||
// Disc art has no state row, so there is no stored content hash — to key the resize cache
|
||||
// on, or to fall back to as a validator. Keying on the id and the album's mtime, as the
|
||||
// legacy reader did, lets a warm cache answer without touching the filesystem; the chain
|
||||
// runs only on a miss. The key carries DiscArtPriority so changing it invalidates.
|
||||
key := fmt.Sprintf("%s|%d|%s", artID.ID, dr.cacheTime().UnixNano(), conf.Server.DiscArtPriority)
|
||||
if size == 0 && !square {
|
||||
r, path, err := selectImage()
|
||||
r, _, err := selectImage()
|
||||
if err != nil || r == nil {
|
||||
return s.Get(ctx, albumArtID, size, square)
|
||||
}
|
||||
return &Image{ReadCloser: r, LastUpdated: unixMtime(mtimeViaFS(dr.lib.FS, path))}, nil
|
||||
return &Image{ReadCloser: r, ETag: representationTag(key, size, square), LastUpdated: dr.cacheTime()}, nil
|
||||
}
|
||||
|
||||
// Disc art has no state row, so there is no stored content hash to key the resize cache on.
|
||||
// Keying on the id and the album's mtime — as the legacy reader did — lets a warm cache
|
||||
// answer without touching the filesystem at all; the chain runs only on a miss. The key
|
||||
// carries DiscArtPriority so changing it invalidates. resizedItem.hash is key material
|
||||
// here, not a content hash, so the response carries no Image.Hash.
|
||||
key := fmt.Sprintf("%s|%d|%s", artID.ID, dr.cacheTime().UnixNano(), conf.Server.DiscArtPriority)
|
||||
item := &resizedItem{
|
||||
hash: key,
|
||||
size: size,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue