🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Add `songCount` column to Artist table
Deluan70047fe20efd
diff --git a/db/migration/20200508093059_add_artist_song_count.go b/db/migration/20200508093059_add_artist_song_count.gonew file mode 100644index 000000000..29d2f0ed2--- /dev/null+++ b/db/migration/20200508093059_add_artist_song_count.go@@ -0,0 +1,27 @@+package migration++import (+ "database/sql"++ "github.com/pressly/goose"+)++func init() {+ goose.AddMigration(Up20200508093059, Down20200508093059)+}++func Up20200508093059(tx *sql.Tx) error {+ _, err := tx.Exec(`+alter table artist+ add song_count integer default 0 not null;+`)+ if err != nil {+ return err+ }+ notice(tx, "A full rescan will be performed to calculate artists' song counts")+ return forceFullRescan(tx)+}++func Down20200508093059(tx *sql.Tx) error {+ return nil+}diff --git a/model/artist.go b/model/artist.goindex 123e9c19d..76f134902 100644--- a/model/artist.go+++ b/model/artist.go@@ -5,7 +5,8 @@ import "time"type Artist struct {ID string `json:"id" orm:"column(id)"`Name string `json:"name"`- AlbumCount int `json:"albumCount" orm:"column(album_count)"`+ AlbumCount int `json:"albumCount"`+ SongCount int `json:"songCount"`FullText string `json:"fullText"`SortArtistName string `json:"sortArtistName"`OrderArtistName string `json:"orderArtistName"`diff --git a/persistence/artist_repository.go b/persistence/artist_repository.goindex 126b73324..3305f70e6 100644--- a/persistence/artist_repository.go+++ b/persistence/artist_repository.go@@ -114,8 +114,8 @@ func (r *artistRepository) Refresh(ids ...string) error {}var artists []refreshArtistsel := Select("f.album_artist_id as id", "f.album_artist as name", "count(*) as album_count", "a.id as current_id",- "f.sort_album_artist_name as sort_artist_name",- "f.order_album_artist_name as order_artist_name").+ "f.sort_album_artist_name as sort_artist_name", "f.order_album_artist_name as order_artist_name",+ "sum(f.song_count) as song_count").From("album f").LeftJoin("artist a on f.album_artist_id = a.id").Where(Eq{"f.album_artist_id": ids}).diff --git a/ui/src/artist/ArtistList.js b/ui/src/artist/ArtistList.jsindex f7f64aba6..fecd8c61e 100644--- a/ui/src/artist/ArtistList.js+++ b/ui/src/artist/ArtistList.js@@ -38,6 +38,7 @@ const ArtistList = (props) => (<Datagrid rowClick={artistRowClick}><TextField source="name" /><NumberField source="albumCount" />+ <NumberField source="songCount" /></Datagrid></List>)diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.jsonindex 43de5b22c..7e11e7a35 100644--- a/ui/src/i18n/en.json+++ b/ui/src/i18n/en.json@@ -49,7 +49,8 @@"name": "Artist |||| Artists","fields": {"name": "Name",- "albumCount": "Album Count"+ "albumCount": "Album Count",+ "songCount": "Song Count"}},"user": {