Skip to content

Commit

Permalink
check route_id only for unlisted tracks (#307)
Browse files Browse the repository at this point in the history
* logic for checking that if track is unlisted then also check route id. else, only rely on track id

* addressing comments

* making filter logic easier to read
  • Loading branch information
vicky-g committed Mar 3, 2020
1 parent ddd6412 commit c3bf2cc
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions discovery-provider/src/queries/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,8 @@ def get_tracks_including_unlisted():

# Create filter conditions as a list of `and` clauses
for i in identifiers:
route_id = helpers.create_track_route_id(i["url_title"], i["handle"])
filter_cond.append(and_(
Track.is_current == True,
Track.route_id == route_id,
Track.track_id == i["id"]
))

Expand All @@ -188,8 +186,25 @@ def get_tracks_including_unlisted():
)

# Perform the query
# TODO: pagination is broken with unlisted tracks
query_results = paginate_query(base_query).all()
tracks = helpers.query_result_to_list(query_results)

# Mapping of track_id -> track object from request;
# used to check route_id when iterating through identifiers
identifiers_map = {track["id"]: track for track in identifiers}

# If the track is unlisted and the generated route_id does not match the route_id in db,
# filter track out from response
def filter_fn(track):
input_track = identifiers_map[track["track_id"]]
route_id = helpers.create_track_route_id(input_track["url_title"], \
input_track["handle"])

return not track["is_unlisted"] or track["route_id"] == route_id

tracks = list(filter(filter_fn, tracks))

track_ids = list(map(lambda track: track["track_id"], tracks))

# Populate metadata
Expand Down

0 comments on commit c3bf2cc

Please sign in to comment.