only return artist cover art if we have cached it

This commit is contained in:
sentriz
2023-09-14 00:32:48 +01:00
parent 5c6a59ac38
commit df2c0707dd
13 changed files with 162 additions and 225 deletions

View File

@@ -52,7 +52,8 @@ type Artist struct {
AlbumCount int `sql:"-"` AlbumCount int `sql:"-"`
ArtistStar *ArtistStar ArtistStar *ArtistStar
ArtistRating *ArtistRating ArtistRating *ArtistRating
AverageRating float64 `sql:"default: null"` AverageRating float64 `sql:"default: null"`
Info *ArtistInfo `gorm:"foreignkey:id"`
} }
func (a *Artist) SID() *specid.ID { func (a *Artist) SID() *specid.ID {

View File

@@ -75,6 +75,7 @@ func (c *Controller) ServeGetArtist(r *http.Request) *spec.Response {
}). }).
Preload("Albums.Artists"). Preload("Albums.Artists").
Preload("Albums.Genres"). Preload("Albums.Genres").
Preload("Info").
Preload("ArtistStar", "user_id=?", user.ID). Preload("ArtistStar", "user_id=?", user.ID).
Preload("ArtistRating", "user_id=?", user.ID). Preload("ArtistRating", "user_id=?", user.ID).
First(artist, id.Value) First(artist, id.Value)
@@ -228,6 +229,7 @@ func (c *Controller) ServeSearchThree(r *http.Request) *spec.Response {
Joins("JOIN albums ON albums.id=album_artists.album_id"). Joins("JOIN albums ON albums.id=album_artists.album_id").
Preload("ArtistStar", "user_id=?", user.ID). Preload("ArtistStar", "user_id=?", user.ID).
Preload("ArtistRating", "user_id=?", user.ID). Preload("ArtistRating", "user_id=?", user.ID).
Preload("Info").
Offset(params.GetOrInt("artistOffset", 0)). Offset(params.GetOrInt("artistOffset", 0)).
Limit(params.GetOrInt("artistCount", 20)) Limit(params.GetOrInt("artistCount", 20))
if m := getMusicFolder(c.MusicPaths, params); m != "" { if m := getMusicFolder(c.MusicPaths, params); m != "" {
@@ -357,22 +359,23 @@ func (c *Controller) ServeGetArtistInfoTwo(r *http.Request) *spec.Response {
Joins("LEFT JOIN album_artists ON album_artists.artist_id=artists.id"). Joins("LEFT JOIN album_artists ON album_artists.artist_id=artists.id").
Joins("LEFT JOIN albums ON albums.id=album_artists.album_id"). Joins("LEFT JOIN albums ON albums.id=album_artists.album_id").
Group("artists.id"). Group("artists.id").
Preload("Info").
Find(&artist). Find(&artist).
Error Error
if errors.Is(err, gorm.ErrRecordNotFound) && !inclNotPresent { if errors.Is(err, gorm.ErrRecordNotFound) && !inclNotPresent {
continue continue
} }
artistID := &specid.ID{}
if artist.ID != 0 { if artist.ID == 0 {
// we don't always have a match if `inclNotPresent` // add a very limited artist, since we don't have everything with `inclNotPresent`
artistID = artist.SID() sub.ArtistInfoTwo.Similar = append(sub.ArtistInfoTwo.Similar, &spec.Artist{
ID: &specid.ID{},
Name: similarName,
})
continue
} }
sub.ArtistInfoTwo.SimilarArtist = append(sub.ArtistInfoTwo.SimilarArtist, &spec.SimilarArtist{
ID: artistID, sub.ArtistInfoTwo.Similar = append(sub.ArtistInfoTwo.Similar, spec.NewArtistByTags(&artist))
Name: similarName,
CoverArt: artistID,
AlbumCount: artist.AlbumCount,
})
} }
return sub return sub
@@ -452,6 +455,7 @@ func (c *Controller) ServeGetStarredTwo(r *http.Request) *spec.Response {
Joins("JOIN albums ON albums.id=album_artists.album_id"). Joins("JOIN albums ON albums.id=album_artists.album_id").
Preload("ArtistStar", "user_id=?", user.ID). Preload("ArtistStar", "user_id=?", user.ID).
Preload("ArtistRating", "user_id=?", user.ID). Preload("ArtistRating", "user_id=?", user.ID).
Preload("Info").
Group("artists.id") Group("artists.id")
if m := getMusicFolder(c.MusicPaths, params); m != "" { if m := getMusicFolder(c.MusicPaths, params); m != "" {
q = q.Where("albums.root_dir=?", m) q = q.Where("albums.root_dir=?", m)

View File

@@ -99,7 +99,9 @@ func NewArtistByTags(a *db.Artist) *Artist {
Name: a.Name, Name: a.Name,
AlbumCount: a.AlbumCount, AlbumCount: a.AlbumCount,
AverageRating: formatRating(a.AverageRating), AverageRating: formatRating(a.AverageRating),
CoverID: a.SID(), }
if a.Info != nil && a.Info.ImageURL != "" {
r.CoverID = a.SID()
} }
if a.ArtistStar != nil { if a.ArtistStar != nil {
r.Starred = &a.ArtistStar.StarDate r.Starred = &a.ArtistStar.StarDate

View File

@@ -284,22 +284,15 @@ type Playlist struct {
List []*TrackChild `xml:"entry,omitempty" json:"entry,omitempty"` List []*TrackChild `xml:"entry,omitempty" json:"entry,omitempty"`
} }
type SimilarArtist struct {
ID *specid.ID `xml:"id,attr" json:"id"`
Name string `xml:"name,attr" json:"name"`
CoverArt *specid.ID `xml:"coverArt,attr" json:"coverArt"`
AlbumCount int `xml:"albumCount,attr,omitempty" json:"albumCount,omitempty"`
}
type ArtistInfo struct { type ArtistInfo struct {
Biography string `xml:"biography" json:"biography"` Biography string `xml:"biography" json:"biography"`
MusicBrainzID string `xml:"musicBrainzId" json:"musicBrainzId"` MusicBrainzID string `xml:"musicBrainzId" json:"musicBrainzId"`
LastFMURL string `xml:"lastFmUrl" json:"lastFmUrl"` LastFMURL string `xml:"lastFmUrl" json:"lastFmUrl"`
SmallImageURL string `xml:"smallImageUrl" json:"smallImageUrl"` SmallImageURL string `xml:"smallImageUrl" json:"smallImageUrl"`
MediumImageURL string `xml:"mediumImageUrl" json:"mediumImageUrl"` MediumImageURL string `xml:"mediumImageUrl" json:"mediumImageUrl"`
LargeImageURL string `xml:"largeImageUrl" json:"largeImageUrl"` LargeImageURL string `xml:"largeImageUrl" json:"largeImageUrl"`
ArtistImageURL string `xml:"artistImageUrl" json:"artistImageUrl"` // not sure where this comes from but other clients seem to expect it ArtistImageURL string `xml:"artistImageUrl" json:"artistImageUrl"` // not sure where this comes from but other clients seem to expect it
SimilarArtist []*SimilarArtist `xml:"similarArtist,omitempty" json:"similarArtist,omitempty"` Similar []*Artist `xml:"similarArtist,omitempty" json:"similarArtist,omitempty"`
} }
type Genres struct { type Genres struct {

View File

@@ -6,58 +6,6 @@
"serverVersion": "", "serverVersion": "",
"albumList": { "albumList": {
"album": [ "album": [
{
"id": "al-8",
"coverArt": "al-8",
"artist": "artist-1",
"created": "2019-11-30T00:00:00Z",
"title": "album-1",
"album": "",
"parent": "al-6",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-7",
"coverArt": "al-7",
"artist": "artist-1",
"created": "2019-11-30T00:00:00Z",
"title": "album-0",
"album": "",
"parent": "al-6",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-9",
"coverArt": "al-9",
"artist": "artist-1",
"created": "2019-11-30T00:00:00Z",
"title": "album-2",
"album": "",
"parent": "al-6",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-4",
"coverArt": "al-4",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-1",
"album": "",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{ {
"id": "al-3", "id": "al-3",
"coverArt": "al-3", "coverArt": "al-3",
@@ -71,32 +19,6 @@
"songCount": 3, "songCount": 3,
"duration": 300 "duration": 300
}, },
{
"id": "al-11",
"coverArt": "al-11",
"artist": "artist-2",
"created": "2019-11-30T00:00:00Z",
"title": "album-0",
"album": "",
"parent": "al-10",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-5",
"coverArt": "al-5",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-2",
"album": "",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{ {
"id": "al-13", "id": "al-13",
"coverArt": "al-13", "coverArt": "al-13",
@@ -110,6 +32,32 @@
"songCount": 3, "songCount": 3,
"duration": 300 "duration": 300
}, },
{
"id": "al-7",
"coverArt": "al-7",
"artist": "artist-1",
"created": "2019-11-30T00:00:00Z",
"title": "album-0",
"album": "",
"parent": "al-6",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-5",
"coverArt": "al-5",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-2",
"album": "",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{ {
"id": "al-12", "id": "al-12",
"coverArt": "al-12", "coverArt": "al-12",
@@ -122,6 +70,58 @@
"name": "", "name": "",
"songCount": 3, "songCount": 3,
"duration": 300 "duration": 300
},
{
"id": "al-8",
"coverArt": "al-8",
"artist": "artist-1",
"created": "2019-11-30T00:00:00Z",
"title": "album-1",
"album": "",
"parent": "al-6",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-9",
"coverArt": "al-9",
"artist": "artist-1",
"created": "2019-11-30T00:00:00Z",
"title": "album-2",
"album": "",
"parent": "al-6",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-11",
"coverArt": "al-11",
"artist": "artist-2",
"created": "2019-11-30T00:00:00Z",
"title": "album-0",
"album": "",
"parent": "al-10",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
},
{
"id": "al-4",
"coverArt": "al-4",
"artist": "artist-0",
"created": "2019-11-30T00:00:00Z",
"title": "album-1",
"album": "",
"parent": "al-2",
"isDir": true,
"name": "",
"songCount": 3,
"duration": 300
} }
] ]
} }

View File

@@ -6,34 +6,6 @@
"serverVersion": "", "serverVersion": "",
"albumList2": { "albumList2": {
"album": [ "album": [
{
"id": "al-3",
"coverArt": "al-3",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-0",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-7",
"coverArt": "al-7",
"artistId": "ar-2",
"artist": "artist-1",
"artists": [{ "id": "ar-2", "name": "artist-1" }],
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-0",
"songCount": 3,
"duration": 300,
"year": 2021
},
{ {
"id": "al-8", "id": "al-8",
"coverArt": "al-8", "coverArt": "al-8",
@@ -63,29 +35,29 @@
"year": 2021 "year": 2021
}, },
{ {
"id": "al-12", "id": "al-5",
"coverArt": "al-12", "coverArt": "al-5",
"artistId": "ar-3", "artistId": "ar-1",
"artist": "artist-2", "artist": "artist-0",
"artists": [{ "id": "ar-3", "name": "artist-2" }], "artists": [{ "id": "ar-1", "name": "artist-0" }],
"created": "2019-11-30T00:00:00Z", "created": "2019-11-30T00:00:00Z",
"title": "", "title": "",
"album": "", "album": "",
"name": "album-1", "name": "album-2",
"songCount": 3, "songCount": 3,
"duration": 300, "duration": 300,
"year": 2021 "year": 2021
}, },
{ {
"id": "al-13", "id": "al-3",
"coverArt": "al-13", "coverArt": "al-3",
"artistId": "ar-3", "artistId": "ar-1",
"artist": "artist-2", "artist": "artist-0",
"artists": [{ "id": "ar-3", "name": "artist-2" }], "artists": [{ "id": "ar-1", "name": "artist-0" }],
"created": "2019-11-30T00:00:00Z", "created": "2019-11-30T00:00:00Z",
"title": "", "title": "",
"album": "", "album": "",
"name": "album-2", "name": "album-0",
"songCount": 3, "songCount": 3,
"duration": 300, "duration": 300,
"year": 2021 "year": 2021
@@ -105,11 +77,25 @@
"year": 2021 "year": 2021
}, },
{ {
"id": "al-5", "id": "al-7",
"coverArt": "al-5", "coverArt": "al-7",
"artistId": "ar-1", "artistId": "ar-2",
"artist": "artist-0", "artist": "artist-1",
"artists": [{ "id": "ar-1", "name": "artist-0" }], "artists": [{ "id": "ar-2", "name": "artist-1" }],
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-0",
"songCount": 3,
"duration": 300,
"year": 2021
},
{
"id": "al-13",
"coverArt": "al-13",
"artistId": "ar-3",
"artist": "artist-2",
"artists": [{ "id": "ar-3", "name": "artist-2" }],
"created": "2019-11-30T00:00:00Z", "created": "2019-11-30T00:00:00Z",
"title": "", "title": "",
"album": "", "album": "",
@@ -131,6 +117,20 @@
"songCount": 3, "songCount": 3,
"duration": 300, "duration": 300,
"year": 2021 "year": 2021
},
{
"id": "al-12",
"coverArt": "al-12",
"artistId": "ar-3",
"artist": "artist-2",
"artists": [{ "id": "ar-3", "name": "artist-2" }],
"created": "2019-11-30T00:00:00Z",
"title": "",
"album": "",
"name": "album-1",
"songCount": 3,
"duration": 300,
"year": 2021
} }
] ]
} }

View File

@@ -7,7 +7,6 @@
"artist": { "artist": {
"id": "ar-1", "id": "ar-1",
"name": "artist-0", "name": "artist-0",
"coverArt": "ar-1",
"albumCount": 3, "albumCount": 3,
"album": [ "album": [
{ {

View File

@@ -7,7 +7,6 @@
"artist": { "artist": {
"id": "ar-3", "id": "ar-3",
"name": "artist-2", "name": "artist-2",
"coverArt": "ar-3",
"albumCount": 3, "albumCount": 3,
"album": [ "album": [
{ {

View File

@@ -7,7 +7,6 @@
"artist": { "artist": {
"id": "ar-2", "id": "ar-2",
"name": "artist-1", "name": "artist-1",
"coverArt": "ar-2",
"albumCount": 3, "albumCount": 3,
"album": [ "album": [
{ {

View File

@@ -10,24 +10,9 @@
{ {
"name": "a", "name": "a",
"artist": [ "artist": [
{ { "id": "ar-1", "name": "artist-0", "albumCount": 6 },
"id": "ar-1", { "id": "ar-2", "name": "artist-1", "albumCount": 6 },
"name": "artist-0", { "id": "ar-3", "name": "artist-2", "albumCount": 6 }
"coverArt": "ar-1",
"albumCount": 6
},
{
"id": "ar-2",
"name": "artist-1",
"coverArt": "ar-2",
"albumCount": 6
},
{
"id": "ar-3",
"name": "artist-2",
"coverArt": "ar-3",
"albumCount": 6
}
] ]
} }
] ]

View File

@@ -10,24 +10,9 @@
{ {
"name": "a", "name": "a",
"artist": [ "artist": [
{ { "id": "ar-1", "name": "artist-0", "albumCount": 3 },
"id": "ar-1", { "id": "ar-2", "name": "artist-1", "albumCount": 3 },
"name": "artist-0", { "id": "ar-3", "name": "artist-2", "albumCount": 3 }
"coverArt": "ar-1",
"albumCount": 3
},
{
"id": "ar-2",
"name": "artist-1",
"coverArt": "ar-2",
"albumCount": 3
},
{
"id": "ar-3",
"name": "artist-2",
"coverArt": "ar-3",
"albumCount": 3
}
] ]
} }
] ]

View File

@@ -10,24 +10,9 @@
{ {
"name": "a", "name": "a",
"artist": [ "artist": [
{ { "id": "ar-1", "name": "artist-0", "albumCount": 3 },
"id": "ar-1", { "id": "ar-2", "name": "artist-1", "albumCount": 3 },
"name": "artist-0", { "id": "ar-3", "name": "artist-2", "albumCount": 3 }
"coverArt": "ar-1",
"albumCount": 3
},
{
"id": "ar-2",
"name": "artist-1",
"coverArt": "ar-2",
"albumCount": 3
},
{
"id": "ar-3",
"name": "artist-2",
"coverArt": "ar-3",
"albumCount": 3
}
] ]
} }
] ]

View File

@@ -6,24 +6,9 @@
"serverVersion": "", "serverVersion": "",
"searchResult3": { "searchResult3": {
"artist": [ "artist": [
{ { "id": "ar-1", "name": "artist-0", "albumCount": 3 },
"id": "ar-1", { "id": "ar-2", "name": "artist-1", "albumCount": 3 },
"name": "artist-0", { "id": "ar-3", "name": "artist-2", "albumCount": 3 }
"coverArt": "ar-1",
"albumCount": 3
},
{
"id": "ar-2",
"name": "artist-1",
"coverArt": "ar-2",
"albumCount": 3
},
{
"id": "ar-3",
"name": "artist-2",
"coverArt": "ar-3",
"albumCount": 3
}
] ]
} }
} }