Skip to content

Commit

Permalink
storage/mariadb: don't return a zero-value DatabaseTrack when using m…
Browse files Browse the repository at this point in the history
…aybeTrackColumns
  • Loading branch information
Wessie committed May 27, 2024
1 parent bcca992 commit 6611610
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion storage/mariadb/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -400,7 +405,7 @@ LIMIT ? OFFSET ?;
var songFavoritesOfDatabaseOnlyQuery = expand(`
SELECT
{songColumns},
{maybeTrackColumns},
{trackColumns},
{lastplayedSelect},
NOW() AS synctime
FROM
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 6611610

Please sign in to comment.