From 1b6ff0c283c8bbea7c6e2f29bf841c154af63c3d Mon Sep 17 00:00:00 2001 From: riwiwa Date: Sun, 1 Mar 2026 15:41:34 -0800 Subject: [PATCH] add unique track count for profiles --- templates/profile.gohtml | 1 + web/profile.go | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/templates/profile.gohtml b/templates/profile.gohtml index d0d56f0..515c3cc 100644 --- a/templates/profile.gohtml +++ b/templates/profile.gohtml @@ -9,6 +9,7 @@

{{formatInt .ScrobbleCount}}

Listens

+

{{formatInt .TrackCount}}

Unique Tracks

{{formatInt .ArtistCount}}

Artists

diff --git a/web/profile.go b/web/profile.go index 5c10bf5..a1a9457 100644 --- a/web/profile.go +++ b/web/profile.go @@ -22,6 +22,7 @@ type ProfileData struct { Pfp string AllowDuplicateEdits bool ScrobbleCount int + TrackCount int ArtistCount int Artists []string Titles []string @@ -72,10 +73,11 @@ func profilePageHandler() http.HandlerFunc { r.Context(), `SELECT bio, pfp, allow_duplicate_edits, (SELECT COUNT(*) FROM history WHERE user_id = $1) as scrobble_count, + (SELECT COUNT(*) FROM songs WHERE user_id = $1) as track_count, (SELECT COUNT(DISTINCT artist) FROM history WHERE user_id = $1) as artist_count FROM users WHERE pk = $1;`, userId, - ).Scan(&profileData.Bio, &profileData.Pfp, &profileData.AllowDuplicateEdits, &profileData.ScrobbleCount, &profileData.ArtistCount) + ).Scan(&profileData.Bio, &profileData.Pfp, &profileData.AllowDuplicateEdits, &profileData.ScrobbleCount, &profileData.TrackCount, &profileData.ArtistCount) if err != nil { fmt.Fprintf(os.Stderr, "Cannot get profile for %s: %v\n", username, err) http.Error(w, err.Error(), http.StatusInternalServerError)