Skip to content

Commit

Permalink
Playlist Trending Fixes (#1336)
Browse files Browse the repository at this point in the history
* Add track_count

* Fix bugs

* PR revisions
  • Loading branch information
piazzatron committed Mar 22, 2021
1 parent 3b8a84d commit 21bd565
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions discovery-provider/src/api/v1/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ def extend_playlist(playlist):
playlist["added_timestamps"] = add_playlist_added_timestamps(playlist)
playlist["cover_art"] = playlist["playlist_image_multihash"]
playlist["cover_art_sizes"] = playlist["playlist_image_sizes_multihash"]
# If a trending playlist, we have 'track_count'
# already to preserve the original, non-abbreviated track count
playlist["track_count"] = (playlist["track_count"] if "track_count"
in playlist else len(playlist["playlist_contents"]["track_ids"]))
return playlist


Expand Down
1 change: 1 addition & 0 deletions discovery-provider/src/api/v1/models/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@
"tracks": fields.List(fields.Nested(track_full), required=True),
"cover_art": fields.String,
"cover_art_sizes": fields.String,
"track_count": fields.Integer(required=True)
})
4 changes: 3 additions & 1 deletion discovery-provider/src/queries/get_trending_playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def get_scorable_playlist_data(session, time_range):
response_name_constants.repost_count: 0,
response_name_constants.windowed_repost_count: 0,
response_name_constants.owner_follower_count: 0,
"karma": 1,
"listens": 1,
} for record in playlists}

Expand Down Expand Up @@ -158,7 +159,7 @@ def wrapped():
playlist_tracks_map = get_playlist_tracks(session, {"playlists": playlists})

for playlist in playlists:
playlist["tracks"] = playlist_tracks_map[playlist["playlist_id"]]
playlist["tracks"] = playlist_tracks_map.get(playlist["playlist_id"], [])

return (playlists, playlist_ids)
return wrapped
Expand Down Expand Up @@ -202,6 +203,7 @@ def get_trending_playlists(args):

trimmed_track_ids = None
for playlist in playlists:
playlist["track_count"] = len(playlist["tracks"])
playlist["tracks"] = playlist["tracks"][:PLAYLIST_TRACKS_LIMIT]
# Trim track_ids, which ultimately become added_timestamps
# and need to match the tracks.
Expand Down

0 comments on commit 21bd565

Please sign in to comment.