diff --git a/cmd/gonic/gonic.go b/cmd/gonic/gonic.go index 7492945b..c594ea85 100644 --- a/cmd/gonic/gonic.go +++ b/cmd/gonic/gonic.go @@ -268,13 +268,7 @@ func main() { if *confExpvar { mux.Handle("/debug/vars", expvar.Handler()) expvar.Publish("stats", expvar.Func(func() any { - var stats struct{ Folders, Albums, Tracks, Artists, InternetRadioStations, Podcasts uint } - dbc.Model(db.Track{}).Count(&stats.Tracks) - dbc.Model(db.Album{}).Count(&stats.Folders) - dbc.Model(db.Album{}).Joins("JOIN album_artists ON album_artists.album_id=albums.id").Group("albums.id").Count(&stats.Albums) - dbc.Model(db.Artist{}).Count(&stats.Artists) - dbc.Model(db.InternetRadioStation{}).Count(&stats.InternetRadioStations) - dbc.Model(db.Podcast{}).Count(&stats.Podcasts) + stats, _ := dbc.Stats() return stats })) } diff --git a/db/db.go b/db/db.go index 2a93b569..ab261aa5 100644 --- a/db/db.go +++ b/db/db.go @@ -80,6 +80,22 @@ func (db *DB) InsertBulkLeftMany(table string, head []string, left int, col []in return db.Exec(q, values...).Error } +type Stats struct { + Folders, Albums, Artists, AlbumArtists, Tracks, InternetRadioStations, Podcasts uint +} + +func (db *DB) Stats() (Stats, error) { + var stats Stats + db.Model(Album{}).Count(&stats.Folders) + db.Model(AlbumArtist{}).Group("album_id").Count(&stats.Albums) + db.Model(TrackArtist{}).Group("artist_id").Count(&stats.Artists) + db.Model(AlbumArtist{}).Group("artist_id").Count(&stats.AlbumArtists) + db.Model(Track{}).Count(&stats.Tracks) + db.Model(InternetRadioStation{}).Count(&stats.InternetRadioStations) + db.Model(Podcast{}).Count(&stats.Podcasts) + return stats, nil +} + func (db *DB) GetUserByID(id int) *User { var user User err := db. diff --git a/server/ctrladmin/adminui/pages/home.tmpl b/server/ctrladmin/adminui/pages/home.tmpl index baa0aaf7..d330d504 100644 --- a/server/ctrladmin/adminui/pages/home.tmpl +++ b/server/ctrladmin/adminui/pages/home.tmpl @@ -7,12 +7,20 @@ "Desc" "total items found in all watched folders" ) }}