fix(db): Include items with no annotation for starred=false, handle has_rating=false (#4921)

* fix(db): Include items with no annotation for starred=false, handle has_rating=false

* hardcode starred instead

* test: ensure albums and artists without annotations are included in starred and has_rating filters

Signed-off-by: Deluan <deluan@navidrome.org>

* refactor: replace starred and has_rating filters with annotationBoolFilter for consistency

Signed-off-by: Deluan <deluan@navidrome.org>

* fix: update annotationBoolFilter to handle boolean values correctly in SQL expressions

Signed-off-by: Deluan <deluan@navidrome.org>

---------

Signed-off-by: Deluan <deluan@navidrome.org>
Co-authored-by: Deluan <deluan@navidrome.org>
This commit is contained in:
Kendall Garner
2026-01-21 10:45:17 -08:00
committed by GitHub
parent 6fce30c133
commit b1b488be77
8 changed files with 342 additions and 8 deletions
+77
View File
@@ -5,6 +5,7 @@ import (
"time"
"github.com/Masterminds/squirrel"
"github.com/deluan/rest"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/model"
@@ -77,6 +78,82 @@ var _ = Describe("AlbumRepository", func() {
})
})
Context("Filters", func() {
var albumWithoutAnnotation model.Album
BeforeEach(func() {
// Create album without any annotation (no star, no rating)
albumWithoutAnnotation = model.Album{ID: "no-annotation-album", Name: "No Annotation", LibraryID: 1}
Expect(albumRepo.Put(&albumWithoutAnnotation)).To(Succeed())
})
AfterEach(func() {
_, _ = albumRepo.executeSQL(squirrel.Delete("album").Where(squirrel.Eq{"id": albumWithoutAnnotation.ID}))
})
Describe("starred", func() {
It("false includes items without annotations", func() {
res, err := albumRepo.ReadAll(rest.QueryOptions{
Filters: map[string]any{"starred": "false"},
})
Expect(err).ToNot(HaveOccurred())
albums := res.(model.Albums)
var found bool
for _, a := range albums {
if a.ID == albumWithoutAnnotation.ID {
found = true
break
}
}
Expect(found).To(BeTrue(), "Album without annotation should be included in starred=false filter")
})
It("true excludes items without annotations", func() {
res, err := albumRepo.ReadAll(rest.QueryOptions{
Filters: map[string]any{"starred": "true"},
})
Expect(err).ToNot(HaveOccurred())
albums := res.(model.Albums)
for _, a := range albums {
Expect(a.ID).ToNot(Equal(albumWithoutAnnotation.ID))
}
})
})
Describe("has_rating", func() {
It("false includes items without annotations", func() {
res, err := albumRepo.ReadAll(rest.QueryOptions{
Filters: map[string]any{"has_rating": "false"},
})
Expect(err).ToNot(HaveOccurred())
albums := res.(model.Albums)
var found bool
for _, a := range albums {
if a.ID == albumWithoutAnnotation.ID {
found = true
break
}
}
Expect(found).To(BeTrue(), "Album without annotation should be included in has_rating=false filter")
})
It("true excludes items without annotations", func() {
res, err := albumRepo.ReadAll(rest.QueryOptions{
Filters: map[string]any{"has_rating": "true"},
})
Expect(err).ToNot(HaveOccurred())
albums := res.(model.Albums)
for _, a := range albums {
Expect(a.ID).ToNot(Equal(albumWithoutAnnotation.ID))
}
})
})
})
Describe("Album.PlayCount", func() {
// Implementation is in withAnnotation() method
DescribeTable("normalizes play count when AlbumPlayCountMode is absolute",