diff --git a/packages/discovery-provider/integration_tests/queries/test_get_user_listening_history.py b/packages/discovery-provider/integration_tests/queries/test_get_user_listening_history.py index 22939d68647..c9568b3daee 100644 --- a/packages/discovery-provider/integration_tests/queries/test_get_user_listening_history.py +++ b/packages/discovery-provider/integration_tests/queries/test_get_user_listening_history.py @@ -355,9 +355,9 @@ def test_track_top_listeners(app): with db.scoped_session() as session: top_listeners = _get_top_listeners_for_track(session, {"track_id": 2}) assert len(top_listeners) == 2 - assert top_listeners[0]["user"]["user_id"] == 2 + assert top_listeners[0]["user"]["user_id"] == 1 assert top_listeners[0]["count"] == 1 - assert top_listeners[1]["user"]["user_id"] == 1 + assert top_listeners[1]["user"]["user_id"] == 2 assert top_listeners[1]["count"] == 1 top_listeners = _get_top_listeners_for_track(session, {"track_id": 1}) diff --git a/packages/discovery-provider/src/api/v1/tracks.py b/packages/discovery-provider/src/api/v1/tracks.py index 880eccd5aff..8f64f365443 100644 --- a/packages/discovery-provider/src/api/v1/tracks.py +++ b/packages/discovery-provider/src/api/v1/tracks.py @@ -1004,7 +1004,7 @@ def get(self, track_id): return success_response(users) -top_listener_response_full = full_ns.model( +top_listener_item = full_ns.model( "full_top_listener", { "count": fields.Integer(required=True), @@ -1012,6 +1012,10 @@ def get(self, track_id): }, ) +top_listener_response_full = make_response( + "full_top_listener", full_ns, fields.List(fields.Nested(top_listener_item)) +) + @full_ns.route("//top_listeners") class FullTrackTopListeners(Resource): diff --git a/packages/discovery-provider/src/queries/get_top_listeners_for_track.py b/packages/discovery-provider/src/queries/get_top_listeners_for_track.py index e83a76161cb..c34d0346f9c 100644 --- a/packages/discovery-provider/src/queries/get_top_listeners_for_track.py +++ b/packages/discovery-provider/src/queries/get_top_listeners_for_track.py @@ -46,7 +46,7 @@ def _get_top_listeners_for_track(session, args): select * from counted left join aggregate_user using (user_id) - order by play_count, follower_count, counted.user_id desc + order by play_count desc, follower_count desc, counted.user_id asc limit :limit offset :offset """ diff --git a/packages/libs/src/sdk/api/generated/full/models/FullTopListener.ts b/packages/libs/src/sdk/api/generated/full/models/FullTopListener.ts index 37c8a4d2d2d..ed6bda3f983 100644 --- a/packages/libs/src/sdk/api/generated/full/models/FullTopListener.ts +++ b/packages/libs/src/sdk/api/generated/full/models/FullTopListener.ts @@ -14,13 +14,6 @@ */ import { exists, mapValues } from '../runtime'; -import type { UserFull } from './UserFull'; -import { - UserFullFromJSON, - UserFullFromJSONTyped, - UserFullToJSON, -} from './UserFull'; - /** * * @export @@ -29,16 +22,10 @@ import { export interface FullTopListener { /** * - * @type {number} - * @memberof FullTopListener - */ - count: number; - /** - * - * @type {UserFull} + * @type {Array} * @memberof FullTopListener */ - user: UserFull; + data?: Array; } /** @@ -46,8 +33,6 @@ export interface FullTopListener { */ export function instanceOfFullTopListener(value: object): boolean { let isInstance = true; - isInstance = isInstance && "count" in value; - isInstance = isInstance && "user" in value; return isInstance; } @@ -62,8 +47,7 @@ export function FullTopListenerFromJSONTyped(json: any, ignoreDiscriminator: boo } return { - 'count': json['count'], - 'user': UserFullFromJSON(json['user']), + 'data': !exists(json, 'data') ? undefined : ((json['data'] as Array).map(FullTopListenerFromJSON)), }; } @@ -76,8 +60,7 @@ export function FullTopListenerToJSON(value?: FullTopListener | null): any { } return { - 'count': value.count, - 'user': UserFullToJSON(value.user), + 'data': value.data === undefined ? undefined : ((value.data as Array).map(FullTopListenerToJSON)), }; }