🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Always fill album's min_year if max_year is filled
Deluan69dc4d97b3a6
diff --git a/persistence/album_repository.go b/persistence/album_repository.goindex 92e699c00..098885ecc 100644--- a/persistence/album_repository.go+++ b/persistence/album_repository.go@@ -2,6 +2,9 @@ package persistenceimport ("context"+ "sort"+ "strconv"+ "strings""time". "github.com/Masterminds/squirrel"@@ -108,12 +111,13 @@ func (r *albumRepository) Refresh(ids ...string) error {CurrentId stringHasCoverArt boolSongArtists string+ Years string}var albums []refreshAlbumsel := Select(`album_id as id, album as name, f.artist, f.album_artist, f.artist_id, f.album_artist_id,- f.compilation, f.genre, max(f.year) as max_year, min(f.year) as min_year, sum(f.duration) as duration,- count(*) as song_count, a.id as current_id, f.id as cover_art_id, f.path as cover_art_path,- group_concat(f.artist, ' ') as song_artists, f.has_cover_art`).+ f.compilation, f.genre, max(f.year) as max_year, sum(f.duration) as duration,+ count(*) as song_count, a.id as current_id, f.id as cover_art_id, f.path as cover_art_path, f.has_cover_art,+ group_concat(f.artist, ' ') as song_artists, group_concat(f.year, ' ') as years`).From("media_file f").LeftJoin("album a on f.album_id = a.id").Where(Eq{"f.album_id": ids}).GroupBy("album_id").OrderBy("f.id")@@ -136,6 +140,7 @@ func (r *albumRepository) Refresh(ids ...string) error {al.AlbumArtist = al.Artistal.AlbumArtistID = al.ArtistID}+ al.MinYear = getMinYear(al.Years)al.UpdatedAt = time.Now()if al.CurrentId != "" {toUpdate++@@ -158,6 +163,18 @@ func (r *albumRepository) Refresh(ids ...string) error {return err}+func getMinYear(years string) int {+ ys := strings.Fields(years)+ sort.Strings(ys)+ for _, y := range ys {+ if y != "0" {+ r, _ := strconv.Atoi(y)+ return r+ }+ }+ return 0+}+func (r *albumRepository) PurgeEmpty() error {del := Delete(r.tableName).Where("id not in (select distinct(album_id) from media_file)")c, err := r.executeSQL(del)diff --git a/persistence/album_repository_test.go b/persistence/album_repository_test.goindex 98222ee3a..1236b57b5 100644--- a/persistence/album_repository_test.go+++ b/persistence/album_repository_test.go@@ -73,4 +73,16 @@ var _ = Describe("AlbumRepository", func() {})})+ Describe("getMinYear", func() {+ It("returns 0 when there's no valid year", func() {+ Expect(getMinYear("a b c")).To(Equal(0))+ Expect(getMinYear("")).To(Equal(0))+ })+ It("returns 0 when all values are 0", func() {+ Expect(getMinYear("0 0 0 ")).To(Equal(0))+ })+ It("returns the smallest value from the list", func() {+ Expect(getMinYear("2000 0 1800")).To(Equal(1800))+ })+ })})