Skip to content

Commit

Permalink
Add back accidentally removed code (#881)
Browse files Browse the repository at this point in the history
  • Loading branch information
jowlee committed Oct 2, 2020
1 parent dad9683 commit d84c860
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
10 changes: 8 additions & 2 deletions discovery-provider/src/queries/get_reposters_for_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ def get_reposters_for_playlist(args):

# Get all Users that reposted Playlist, ordered by follower_count desc & paginated.
query = (
session.query(User)
session.query(
User,
# Replace null values from left outer join with 0 to ensure sort works correctly.
(func.coalesce(follower_count_subquery.c.follower_count, 0)).label(
response_name_constants.follower_count)
)
# Left outer join to associate users with their follower count.
.outerjoin(follower_count_subquery, follower_count_subquery.c.followee_user_id == User.user_id)
.filter(
Expand All @@ -65,7 +70,8 @@ def get_reposters_for_playlist(args):

# Fix format to return only Users objects with follower_count field.
if user_results:
user_results = helpers.query_result_to_list(user_results)
users, _ = zip(*user_results)
user_results = helpers.query_result_to_list(users)
# bundle peripheral info into user results
user_ids = [user['user_id'] for user in user_results]
user_results = populate_user_metadata(
Expand Down
10 changes: 8 additions & 2 deletions discovery-provider/src/queries/get_reposters_for_track.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ def get_reposters_for_track(args):

# Get all Users that reposted track, ordered by follower_count desc & paginated.
query = (
session.query(User)
session.query(
User,
# Replace null values from left outer join with 0 to ensure sort works correctly.
(func.coalesce(follower_count_subquery.c.follower_count, 0)).label(
response_name_constants.follower_count)
)
# Left outer join to associate users with their follower count.
.outerjoin(follower_count_subquery, follower_count_subquery.c.followee_user_id == User.user_id)
.filter(
Expand All @@ -64,7 +69,8 @@ def get_reposters_for_track(args):

# Fix format to return only Users objects with follower_count field.
if user_results:
user_results = helpers.query_result_to_list(user_results)
users, _ = zip(*user_results)
user_results = helpers.query_result_to_list(users)
# bundle peripheral info into user results
user_ids = [user['user_id'] for user in user_results]
user_results = populate_user_metadata(
Expand Down
8 changes: 7 additions & 1 deletion discovery-provider/src/queries/get_savers_for_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ def get_savers_for_playlist(args):

# Get all Users that saved Playlist, ordered by follower_count desc & paginated.
query = (
session.query(User)
session.query(
User,
# Replace null values from left outer join with 0 to ensure sort works correctly.
(func.coalesce(follower_count_subquery.c.follower_count, 0))
.label(response_name_constants.follower_count)
)
# Left outer join to associate users with their follower count.
.outerjoin(follower_count_subquery, follower_count_subquery.c.followee_user_id == User.user_id)
.filter(
Expand All @@ -64,6 +69,7 @@ def get_savers_for_playlist(args):

# Fix format to return only Users objects with follower_count field.
if user_results:
users, _ = zip(*user_results)
user_results = helpers.query_result_to_list(user_results)
# bundle peripheral info into user results
user_ids = [user['user_id'] for user in user_results]
Expand Down
10 changes: 8 additions & 2 deletions discovery-provider/src/queries/get_savers_for_track.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ def get_savers_for_track(args):

# Get all Users that saved track, ordered by follower_count desc & paginated.
query = (
session.query(User)
session.query(
User,
# Replace null values from left outer join with 0 to ensure sort works correctly.
(func.coalesce(follower_count_subquery.c.follower_count, 0)).label(
response_name_constants.follower_count)
)
# Left outer join to associate users with their follower count.
.outerjoin(follower_count_subquery, follower_count_subquery.c.followee_user_id == User.user_id)
.filter(
Expand All @@ -63,7 +68,8 @@ def get_savers_for_track(args):

# Fix format to return only Users objects with follower_count field.
if user_results:
user_results = helpers.query_result_to_list(user_results)
users, _ = zip(*user_results)
user_results = helpers.query_result_to_list(users)
# bundle peripheral info into user results
user_ids = [user['user_id'] for user in user_results]
user_results = populate_user_metadata(
Expand Down

0 comments on commit d84c860

Please sign in to comment.