add some basic children counts
This commit is contained in:
@@ -9,8 +9,9 @@ import (
|
|||||||
|
|
||||||
type Artist struct {
|
type Artist struct {
|
||||||
IDBase
|
IDBase
|
||||||
Name string `gorm:"not null; unique_index"`
|
Name string `gorm:"not null; unique_index"`
|
||||||
Albums []*Album `gorm:"foreignkey:TagArtistID"`
|
Albums []*Album `gorm:"foreignkey:TagArtistID"`
|
||||||
|
AlbumCount int `sql:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Track struct {
|
type Track struct {
|
||||||
@@ -81,6 +82,7 @@ type Album struct {
|
|||||||
TagTitle string `gorm:"index" sql:"default: null"`
|
TagTitle string `gorm:"index" sql:"default: null"`
|
||||||
TagYear int `sql:"default: null"`
|
TagYear int `sql:"default: null"`
|
||||||
Tracks []*Track
|
Tracks []*Track
|
||||||
|
ChildCount int `sql:"-"`
|
||||||
ReceivedPaths bool `gorm:"-"`
|
ReceivedPaths bool `gorm:"-"`
|
||||||
ReceivedTags bool `gorm:"-"`
|
ReceivedTags bool `gorm:"-"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,8 +61,9 @@ func newTCTrackByFolder(t *model.Track, parent *model.Album) *subsonic.TrackChil
|
|||||||
|
|
||||||
func newArtistByFolder(f *model.Album) *subsonic.Artist {
|
func newArtistByFolder(f *model.Album) *subsonic.Artist {
|
||||||
return &subsonic.Artist{
|
return &subsonic.Artist{
|
||||||
ID: f.ID,
|
ID: f.ID,
|
||||||
Name: f.RightPath,
|
Name: f.RightPath,
|
||||||
|
AlbumCount: f.ChildCount,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ func newTrackByTags(t *model.Track, album *model.Album) *subsonic.TrackChild {
|
|||||||
|
|
||||||
func newArtistByTags(a *model.Artist) *subsonic.Artist {
|
func newArtistByTags(a *model.Artist) *subsonic.Artist {
|
||||||
return &subsonic.Artist{
|
return &subsonic.Artist{
|
||||||
ID: a.ID,
|
ID: a.ID,
|
||||||
Name: a.Name,
|
Name: a.Name,
|
||||||
|
AlbumCount: a.AlbumCount,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,15 @@ import (
|
|||||||
|
|
||||||
func (c *Controller) GetIndexes(w http.ResponseWriter, r *http.Request) {
|
func (c *Controller) GetIndexes(w http.ResponseWriter, r *http.Request) {
|
||||||
var folders []*model.Album
|
var folders []*model.Album
|
||||||
|
|
||||||
c.DB.
|
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)
|
Find(&folders)
|
||||||
indexMap := make(map[string]*subsonic.Index)
|
indexMap := make(map[string]*subsonic.Index)
|
||||||
indexes := []*subsonic.Index{}
|
indexes := []*subsonic.Index{}
|
||||||
|
|||||||
@@ -14,7 +14,14 @@ import (
|
|||||||
|
|
||||||
func (c *Controller) GetArtists(w http.ResponseWriter, r *http.Request) {
|
func (c *Controller) GetArtists(w http.ResponseWriter, r *http.Request) {
|
||||||
var artists []*model.Artist
|
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)
|
indexMap := make(map[string]*subsonic.Index)
|
||||||
indexes := &subsonic.Artists{}
|
indexes := &subsonic.Artists{}
|
||||||
for _, artist := range artists {
|
for _, artist := range artists {
|
||||||
|
|||||||
Reference in New Issue
Block a user