mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 21:17:37 +03:00
Order albums by full original date. Fixes #1452
This commit is contained in:
parent
11f33ff8b6
commit
7d0656f44a
3 changed files with 12 additions and 6 deletions
|
@ -27,7 +27,7 @@ func NewAlbumRepository(ctx context.Context, o orm.QueryExecutor) model.AlbumRep
|
||||||
"name": "order_album_name asc, order_album_artist_name asc",
|
"name": "order_album_name asc, order_album_artist_name asc",
|
||||||
"artist": "compilation asc, order_album_artist_name asc, order_album_name asc",
|
"artist": "compilation asc, order_album_artist_name asc, order_album_name asc",
|
||||||
"random": "RANDOM()",
|
"random": "RANDOM()",
|
||||||
"max_year": "max_year asc, name, order_album_name asc",
|
"max_year": "max_year, coalesce(nullif(original_date, ''), nullif(release_date, '')), name, order_album_name asc",
|
||||||
"recently_added": recentlyAddedSort(),
|
"recently_added": recentlyAddedSort(),
|
||||||
}
|
}
|
||||||
r.filterMappings = map[string]filterFunc{
|
r.filterMappings = map[string]filterFunc{
|
||||||
|
|
|
@ -97,14 +97,16 @@ func (r sqlRepository) buildSortOrder(sort, order string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func splitFunc(delimiter rune) func(c rune) bool {
|
func splitFunc(delimiter rune) func(c rune) bool {
|
||||||
open := false
|
open := 0
|
||||||
return func(c rune) bool {
|
return func(c rune) bool {
|
||||||
if open {
|
if c == '(' {
|
||||||
open = c != ')'
|
open++
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if c == '(' {
|
if open > 0 {
|
||||||
open = true
|
if c == ')' {
|
||||||
|
open--
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return c == delimiter
|
return c == delimiter
|
||||||
|
|
|
@ -69,6 +69,10 @@ var _ = Describe("sqlRepository", func() {
|
||||||
sql := r.buildSortOrder("name desc, substr(id, 7), status asc", "desc")
|
sql := r.buildSortOrder("name desc, substr(id, 7), status asc", "desc")
|
||||||
Expect(sql).To(Equal("name asc, substr(id, 7) desc, status desc"))
|
Expect(sql).To(Equal("name asc, substr(id, 7) desc, status desc"))
|
||||||
})
|
})
|
||||||
|
It("handles nested functions", func() {
|
||||||
|
sql := r.buildSortOrder("name desc, coalesce(nullif(release_date, ''), nullif(original_date, '')), status asc", "desc")
|
||||||
|
Expect(sql).To(Equal("name asc, coalesce(nullif(release_date, ''), nullif(original_date, '')) desc, status desc"))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue