3 Commits
5 changed files with 30 additions and 45 deletions

No files matched your search

+7 -1
View File
@@ -30,7 +30,13 @@ type Client struct {
}
func NewClient() *Client {
return NewClientCustom(http.DefaultClient)
// disable keep-alive to avoid "connection reset by peer" errors caused by a race between
// the server closing idle connections and the client reusing them for new requests
return NewClientCustom(&http.Client{
Transport: &http.Transport{
DisableKeepAlives: true,
},
})
}
func NewClientCustom(httpClient *http.Client) *Client {
+19 -31
View File
@@ -320,56 +320,44 @@ func (c *Controller) ServeGetStarred(r *http.Request) *spec.Response {
results := &spec.Starred{}
// "artists"
var artists []*db.Artist
q := c.dbc.
Select("artists.*, count(albums.id) album_count").
Joins("JOIN artist_stars ON artist_stars.artist_id=artists.id").
Where("artist_stars.user_id=?", user.ID).
Joins("JOIN artist_appearances ON artist_appearances.artist_id=artists.id").
Joins("JOIN albums ON albums.id=artist_appearances.album_id").
Order("artist_stars.star_date DESC").
Preload("ArtistStar", "user_id=?", user.ID).
Preload("ArtistRating", "user_id=?", user.ID).
Preload("Info").
Group("artists.id")
rootQ := c.dbc.
Select("id").
Model(&db.Album{}).
Where("parent_id IS NULL")
if m := getMusicFolder(c, params); m != "" {
q = q.Where("albums.root_dir=?", m)
rootQ = rootQ.Where("root_dir=?", m)
}
var artists []*db.Album
q := c.dbc.
Where(`parent_id IN ?`, rootQ.SubQuery()).
Joins("JOIN album_stars ON albums.id=album_stars.album_id").
Where("album_stars.user_id=?", user.ID).
Preload("AlbumStar", "user_id=?", user.ID).
Preload("AlbumRating", "user_id=?", user.ID)
if err := q.Find(&artists).Error; err != nil {
return spec.NewError(0, "find artists: %v", err)
}
for _, a := range artists {
results.Artists = append(results.Artists, spec.NewArtistByTags(a))
results.Artists = append(results.Artists, spec.NewDirectoryByFolder(a, nil))
}
// "albums"
var albums []*db.Album
q = c.dbc.Where("parent_id IS NOT NULL").
Joins("JOIN album_stars ON albums.id=album_stars.album_id AND album_stars.user_id=?", user.ID)
q = q.Order("album_stars.star_date DESC")
q = q.
q = c.dbc.
Joins("JOIN album_artists ON album_artists.album_id=albums.id").
Joins("JOIN album_stars ON albums.id=album_stars.album_id").
Where("album_stars.user_id=?", user.ID).
Preload("AlbumStar", "user_id=?", user.ID).
Preload("AlbumRating", "user_id=?", user.ID)
if m := getMusicFolder(c, params); m != "" {
q = q.Where("root_dir=?", m)
}
q.
Select("albums.*, count(tracks.id) child_count, sum(tracks.length) duration").
Joins("LEFT JOIN tracks ON tracks.album_id=albums.id").
Group("albums.id").
Joins("JOIN album_artists ON album_artists.album_id=albums.id").
Preload("Parent").
Preload("AlbumStar", "user_id=?", user.ID).
Preload("AlbumRating", "user_id=?", user.ID)
if err := q.Find(&albums).Error; err != nil {
return spec.NewError(0, "find albums: %v", err)
}
for _, a := range albums {
results.Albums = append(results.Albums, spec.NewAlbumByFolder(a))
results.Albums = append(results.Albums, spec.NewTCAlbumByFolder(a))
}
// tracks
-1
View File
@@ -28,7 +28,6 @@ func (c *Controller) ServeGetArtists(r *http.Request) *spec.Response {
q := c.dbc.
Select("*, count(album_artists.album_id) album_count").
Joins("JOIN album_artists ON album_artists.artist_id=artists.id").
Joins("LEFT JOIN artist_stars ON artist_stars.artist_id=artists.id").
Preload("ArtistStar", "user_id=?", user.ID).
Preload("ArtistRating", "user_id=?", user.ID).
Preload("Info").
@@ -6,22 +6,14 @@ import (
"sort"
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/server/ctrlsubsonic/specid"
)
func NewAlbumByFolder(f *db.Album) *Album {
artist := ""
var parentSID *specid.ID
if f.Parent != nil {
artist = f.Parent.RightPath
parentSID = f.ParentSID()
}
a := &Album{
Artist: artist,
Artist: f.Parent.RightPath,
ID: f.SID(),
IsDir: true,
ParentID: parentSID,
ParentID: f.ParentSID(),
Album: f.RightPath,
Name: f.RightPath,
Title: f.RightPath,
+2 -2
View File
@@ -442,8 +442,8 @@ type Bookmark struct {
}
type Starred struct {
Artists []*Artist `xml:"artist,omitempty" json:"artist,omitempty"`
Albums []*Album `xml:"album,omitempty" json:"album,omitempty"`
Artists []*Directory `xml:"artist,omitempty" json:"artist,omitempty"`
Albums []*TrackChild `xml:"album,omitempty" json:"album,omitempty"`
Tracks []*TrackChild `xml:"song,omitempty" json:"song,omitempty"`
}