set the size of indexes
This commit is contained in:
@@ -29,10 +29,11 @@ func (c *Controller) GetIndexes(w http.ResponseWriter, r *http.Request) {
|
|||||||
Where("albums.parent_id = 1").
|
Where("albums.parent_id = 1").
|
||||||
Group("albums.id").
|
Group("albums.id").
|
||||||
Find(&folders)
|
Find(&folders)
|
||||||
indexMap := make(map[string]*subsonic.Index)
|
// [a-z#] -> 27
|
||||||
indexes := []*subsonic.Index{}
|
indexMap := make(map[string]*subsonic.Index, 27)
|
||||||
|
resp := make([]*subsonic.Index, 0, 27)
|
||||||
for _, folder := range folders {
|
for _, folder := range folders {
|
||||||
i := indexOf(folder.IndexRightPath())
|
i := lowerUDecOrHash(folder.IndexRightPath())
|
||||||
index, ok := indexMap[i]
|
index, ok := indexMap[i]
|
||||||
if !ok {
|
if !ok {
|
||||||
index = &subsonic.Index{
|
index = &subsonic.Index{
|
||||||
@@ -40,18 +41,18 @@ func (c *Controller) GetIndexes(w http.ResponseWriter, r *http.Request) {
|
|||||||
Artists: []*subsonic.Artist{},
|
Artists: []*subsonic.Artist{},
|
||||||
}
|
}
|
||||||
indexMap[i] = index
|
indexMap[i] = index
|
||||||
indexes = append(indexes, index)
|
resp = append(resp, index)
|
||||||
}
|
}
|
||||||
index.Artists = append(index.Artists,
|
index.Artists = append(index.Artists,
|
||||||
newArtistByFolder(folder))
|
newArtistByFolder(folder))
|
||||||
}
|
}
|
||||||
sort.Slice(indexes, func(i, j int) bool {
|
sort.Slice(resp, func(i, j int) bool {
|
||||||
return indexes[i].Name < indexes[j].Name
|
return resp[i].Name < resp[j].Name
|
||||||
})
|
})
|
||||||
sub := subsonic.NewResponse()
|
sub := subsonic.NewResponse()
|
||||||
sub.Indexes = &subsonic.Indexes{
|
sub.Indexes = &subsonic.Indexes{
|
||||||
LastModified: 0,
|
LastModified: 0,
|
||||||
Index: indexes,
|
Index: resp,
|
||||||
}
|
}
|
||||||
respond(w, r, sub)
|
respond(w, r, sub)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,10 +22,11 @@ func (c *Controller) GetArtists(w http.ResponseWriter, r *http.Request) {
|
|||||||
`).
|
`).
|
||||||
Group("artists.id").
|
Group("artists.id").
|
||||||
Find(&artists)
|
Find(&artists)
|
||||||
indexMap := make(map[string]*subsonic.Index)
|
// [a-z#] -> 27
|
||||||
indexes := &subsonic.Artists{}
|
indexMap := make(map[string]*subsonic.Index, 27)
|
||||||
|
resp := make([]*subsonic.Index, 0, 27)
|
||||||
for _, artist := range artists {
|
for _, artist := range artists {
|
||||||
i := indexOf(artist.IndexName())
|
i := lowerUDecOrHash(artist.IndexName())
|
||||||
index, ok := indexMap[i]
|
index, ok := indexMap[i]
|
||||||
if !ok {
|
if !ok {
|
||||||
index = &subsonic.Index{
|
index = &subsonic.Index{
|
||||||
@@ -33,16 +34,18 @@ func (c *Controller) GetArtists(w http.ResponseWriter, r *http.Request) {
|
|||||||
Artists: []*subsonic.Artist{},
|
Artists: []*subsonic.Artist{},
|
||||||
}
|
}
|
||||||
indexMap[i] = index
|
indexMap[i] = index
|
||||||
indexes.List = append(indexes.List, index)
|
resp = append(resp, index)
|
||||||
}
|
}
|
||||||
index.Artists = append(index.Artists,
|
index.Artists = append(index.Artists,
|
||||||
newArtistByTags(artist))
|
newArtistByTags(artist))
|
||||||
}
|
}
|
||||||
sort.Slice(indexes.List, func(i, j int) bool {
|
sort.Slice(resp, func(i, j int) bool {
|
||||||
return indexes.List[i].Name < indexes.List[j].Name
|
return resp[i].Name < resp[j].Name
|
||||||
})
|
})
|
||||||
sub := subsonic.NewResponse()
|
sub := subsonic.NewResponse()
|
||||||
sub.Artists = indexes
|
sub.Artists = &subsonic.Artists{
|
||||||
|
List: resp,
|
||||||
|
}
|
||||||
respond(w, r, sub)
|
respond(w, r, sub)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import (
|
|||||||
"github.com/sentriz/gonic/server/subsonic"
|
"github.com/sentriz/gonic/server/subsonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
func indexOf(in string) string {
|
func lowerUDecOrHash(in string) string {
|
||||||
lower := unicode.ToLower(rune(in[0]))
|
lower := unicode.ToLower(rune(in[0]))
|
||||||
if !unicode.IsLetter(lower) {
|
if !unicode.IsLetter(lower) {
|
||||||
return "#"
|
return "#"
|
||||||
|
|||||||
Reference in New Issue
Block a user