From 661161082ec65fc5d6f037ecaa1f6f56b13a9845 Mon Sep 17 00:00:00 2001 From: Wessie Date: Mon, 27 May 2024 01:08:42 +0100 Subject: [PATCH] storage/mariadb: don't return a zero-value DatabaseTrack when using maybeTrackColumns --- storage/mariadb/track.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/storage/mariadb/track.go b/storage/mariadb/track.go index 0e94fc4f..e3adaa83 100644 --- a/storage/mariadb/track.go +++ b/storage/mariadb/track.go @@ -164,6 +164,11 @@ func (ss SongStorage) FromHash(hash radio.SongHash) (*radio.Song, error) { } return nil, errors.E(op, err) } + // remove a DatabaseTrack if we allocated it but it ended up being + // zero + if song.HasTrack() && song.TrackID == 0 { + song.DatabaseTrack = nil + } return &song, nil } @@ -400,7 +405,7 @@ LIMIT ? OFFSET ?; var songFavoritesOfDatabaseOnlyQuery = expand(` SELECT {songColumns}, - {maybeTrackColumns}, + {trackColumns}, {lastplayedSelect}, NOW() AS synctime FROM @@ -446,6 +451,12 @@ func (ss SongStorage) FavoritesOf(nick string, limit, offset int64) ([]radio.Son return nil, 0, errors.E(op, err) } + for i := range songs { + if songs[i].DatabaseTrack != nil && songs[i].TrackID == 0 { + songs[i].DatabaseTrack = nil + } + } + return songs, count, nil }