From ea1451ab76494f210a3872bc94b7d5b33ce76c25 Mon Sep 17 00:00:00 2001 From: Daniel Mason Date: Sun, 9 Jan 2022 11:24:36 +1300 Subject: [PATCH] 0.1.6 - Allow UUID of 0 in artists/{uuid}/top to return site-wide stats - Set images as failed if cannot find in spotify to prevent oversearching --- .gitlab-ci.yml | 2 +- docs/changelog.md | 4 ++++ internal/goscrobble/artist.go | 27 +++++++++++++++----------- internal/goscrobble/ingress_spotify.go | 6 ++++-- internal/goscrobble/server.go | 2 +- internal/goscrobble/track.go | 26 ++++++++++++++----------- 6 files changed, 41 insertions(+), 26 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b8ff94f1..f1a9586a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ stages: - build variables: - VERSION: 0.1.51 + VERSION: 0.1.6 build-go: image: golang:1.17 diff --git a/docs/changelog.md b/docs/changelog.md index 9957ff57..a75f214b 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,3 +1,7 @@ +# 0.1.6 +- Allow UUID of 0 in artists/{uuid}/top to return site-wide stats +- Set images as failed if cannot find in spotify to prevent oversearching + # 0.1.51 - Fixed image resize to maintain aspect ratio diff --git a/internal/goscrobble/artist.go b/internal/goscrobble/artist.go index d68d8e82..64477159 100644 --- a/internal/goscrobble/artist.go +++ b/internal/goscrobble/artist.go @@ -132,6 +132,7 @@ func getArtistByUUID(uuid string) (Artist, error) { return artist, nil } +// getTopArtists - 0 UUID will return all func getTopArtists(userUuid string, dayRange string) (TopArtists, error) { var topArtist TopArtists @@ -140,17 +141,21 @@ func getTopArtists(userUuid string, dayRange string) (TopArtists, error) { dateClause = " AND DATE(created_at) > SUBDATE(CURRENT_DATE, " + dayRange + ") " } - rows, err := db.Query("SELECT BIN_TO_UUID(`artists`.`uuid`, true), `artists`.`name`, IFNULL(BIN_TO_UUID(`artists`.`uuid`, true),''), count(*) "+ - "FROM `scrobbles` "+ - "JOIN `tracks` ON `tracks`.`uuid` = `scrobbles`.`track` "+ - "JOIN track_artist ON track_artist.track = tracks.uuid "+ - "JOIN artists ON track_artist.artist = artists.uuid "+ - "WHERE `scrobbles`.`user` = UUID_TO_BIN(?, true) "+ - dateClause+ - "GROUP BY `artists`.`uuid` "+ - "ORDER BY count(*) DESC "+ - "LIMIT 14;", - userUuid) + whereClause := "" + if userUuid != "0" { + whereClause = "WHERE `scrobbles`.`user` = UUID_TO_BIN('" + userUuid + "', true) " + } + + rows, err := db.Query("SELECT BIN_TO_UUID(`artists`.`uuid`, true), `artists`.`name`, IFNULL(BIN_TO_UUID(`artists`.`uuid`, true),''), count(*) " + + "FROM `scrobbles` " + + "JOIN `tracks` ON `tracks`.`uuid` = `scrobbles`.`track` " + + "JOIN track_artist ON track_artist.track = tracks.uuid " + + "JOIN artists ON track_artist.artist = artists.uuid " + + whereClause + + dateClause + + "GROUP BY `artists`.`uuid` " + + "ORDER BY count(*) DESC " + + "LIMIT 14;") if err != nil { log.Printf("Failed to fetch top artist: %+v", err) return topArtist, errors.New("Failed to fetch top artist") diff --git a/internal/goscrobble/ingress_spotify.go b/internal/goscrobble/ingress_spotify.go index edb4099d..4ed13a89 100644 --- a/internal/goscrobble/ingress_spotify.go +++ b/internal/goscrobble/ingress_spotify.go @@ -270,8 +270,9 @@ func (user *User) updateImageDataFromSpotify() { if len(res.Artists.Artists[0].Images) > 0 { toUpdate[uuid] = res.Artists.Artists[0].Images[0].URL } + } else { + _, _ = db.Exec("UPDATE `artists` SET `img` = 'none' WHERE `uuid` = UUID_TO_BIN(?,true)", uuid) } - } rows.Close() @@ -314,8 +315,9 @@ func (user *User) updateImageDataFromSpotify() { if len(res.Albums.Albums[0].Images) > 0 { toUpdate[uuid] = res.Albums.Albums[0].Images[0].URL } + } else { + _, _ = db.Exec("UPDATE `albums` SET `img` = 'none' WHERE `uuid` = UUID_TO_BIN(?,true)", uuid) } - } rows.Close() diff --git a/internal/goscrobble/server.go b/internal/goscrobble/server.go index 3e0cc6be..7daa1882 100644 --- a/internal/goscrobble/server.go +++ b/internal/goscrobble/server.go @@ -825,7 +825,7 @@ func getServerInfo(w http.ResponseWriter, r *http.Request) { } info := ServerInfo{ - Version: "0.1.51", + Version: "0.1.6", RegistrationEnabled: registrationEnabled, } diff --git a/internal/goscrobble/track.go b/internal/goscrobble/track.go index b4527df3..898037eb 100644 --- a/internal/goscrobble/track.go +++ b/internal/goscrobble/track.go @@ -192,17 +192,21 @@ func getTopTracks(userUuid string, dayRange string) (TopTracks, error) { dateClause = " AND DATE(created_at) > SUBDATE(CURRENT_DATE, " + dayRange + ") " } - rows, err := db.Query("SELECT BIN_TO_UUID(`tracks`.`uuid`, true), `tracks`.`name`, IFNULL(BIN_TO_UUID(`albums`.`uuid`, true),''), count(*) "+ - "FROM `scrobbles` "+ - "JOIN `tracks` ON `tracks`.`uuid` = `scrobbles`.`track` "+ - "JOIN track_album ON track_album.track = tracks.uuid "+ - "JOIN albums ON track_album.album = albums.uuid "+ - "WHERE `user` = UUID_TO_BIN(?, true) "+ - dateClause+ - "GROUP BY `scrobbles`.`track` "+ - "ORDER BY count(*) DESC "+ - "LIMIT 14", - userUuid) + whereClause := "" + if userUuid != "0" { + whereClause = "WHERE `scrobbles`.`user` = UUID_TO_BIN('" + userUuid + "', true) " + } + + rows, err := db.Query("SELECT BIN_TO_UUID(`tracks`.`uuid`, true), `tracks`.`name`, IFNULL(BIN_TO_UUID(`albums`.`uuid`, true),''), count(*) " + + "FROM `scrobbles` " + + "JOIN `tracks` ON `tracks`.`uuid` = `scrobbles`.`track` " + + "JOIN track_album ON track_album.track = tracks.uuid " + + "JOIN albums ON track_album.album = albums.uuid " + + whereClause + + dateClause + + "GROUP BY `scrobbles`.`track` " + + "ORDER BY count(*) DESC " + + "LIMIT 14") if err != nil { log.Printf("Failed to fetch top tracks: %+v", err)