add some basic children counts
This commit is contained in:
@@ -11,6 +11,7 @@ type Artist struct {
|
||||
IDBase
|
||||
Name string `gorm:"not null; unique_index"`
|
||||
Albums []*Album `gorm:"foreignkey:TagArtistID"`
|
||||
AlbumCount int `sql:"-"`
|
||||
}
|
||||
|
||||
type Track struct {
|
||||
@@ -81,6 +82,7 @@ type Album struct {
|
||||
TagTitle string `gorm:"index" sql:"default: null"`
|
||||
TagYear int `sql:"default: null"`
|
||||
Tracks []*Track
|
||||
ChildCount int `sql:"-"`
|
||||
ReceivedPaths bool `gorm:"-"`
|
||||
ReceivedTags bool `gorm:"-"`
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ func newArtistByFolder(f *model.Album) *subsonic.Artist {
|
||||
return &subsonic.Artist{
|
||||
ID: f.ID,
|
||||
Name: f.RightPath,
|
||||
AlbumCount: f.ChildCount,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,5 +57,6 @@ func newArtistByTags(a *model.Artist) *subsonic.Artist {
|
||||
return &subsonic.Artist{
|
||||
ID: a.ID,
|
||||
Name: a.Name,
|
||||
AlbumCount: a.AlbumCount,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,15 @@ import (
|
||||
|
||||
func (c *Controller) GetIndexes(w http.ResponseWriter, r *http.Request) {
|
||||
var folders []*model.Album
|
||||
|
||||
c.DB.
|
||||
Where("parent_id = 1").
|
||||
Select("*, count(sub.id) as child_count").
|
||||
Joins(`
|
||||
LEFT JOIN albums sub
|
||||
ON albums.id = sub.parent_id
|
||||
`).
|
||||
Where("albums.parent_id = 1").
|
||||
Group("albums.id").
|
||||
Find(&folders)
|
||||
indexMap := make(map[string]*subsonic.Index)
|
||||
indexes := []*subsonic.Index{}
|
||||
|
||||
@@ -14,7 +14,14 @@ import (
|
||||
|
||||
func (c *Controller) GetArtists(w http.ResponseWriter, r *http.Request) {
|
||||
var artists []*model.Artist
|
||||
c.DB.Find(&artists)
|
||||
c.DB.
|
||||
Select("*, count(sub.id) as album_count").
|
||||
Joins(`
|
||||
LEFT JOIN albums sub
|
||||
ON artists.id = sub.tag_artist_id
|
||||
`).
|
||||
Group("artists.id").
|
||||
Find(&artists)
|
||||
indexMap := make(map[string]*subsonic.Index)
|
||||
indexes := &subsonic.Artists{}
|
||||
for _, artist := range artists {
|
||||
|
||||
Reference in New Issue
Block a user