diff --git a/discovery-provider/src/queries/get_trending_tracks.py b/discovery-provider/src/queries/get_trending_tracks.py index d8ee2158936..548dc4ac65b 100644 --- a/discovery-provider/src/queries/get_trending_tracks.py +++ b/discovery-provider/src/queries/get_trending_tracks.py @@ -68,7 +68,11 @@ def generate_unpopulated_trending_from_mat_views( top_listen_tracks_subquery = top_listen_tracks_subquery.order_by( desc(AggregateIntervalPlay.year_listen_counts) ) - top_listen_tracks_subquery = top_listen_tracks_subquery.limit(limit) + + score_params = strategy.get_score_params() + nm = score_params["nm"] + + top_listen_tracks_subquery = top_listen_tracks_subquery.limit(limit * nm) trending_track_ids_query = session.query( TrackTrendingScore.track_id, TrackTrendingScore.score diff --git a/discovery-provider/src/trending_strategies/aSPET_trending_tracks_strategy.py b/discovery-provider/src/trending_strategies/aSPET_trending_tracks_strategy.py index 3bb0f572336..74c5fab01c9 100644 --- a/discovery-provider/src/trending_strategies/aSPET_trending_tracks_strategy.py +++ b/discovery-provider/src/trending_strategies/aSPET_trending_tracks_strategy.py @@ -48,8 +48,8 @@ def update_track_score_query(self, session): CASE WHEN tp.owner_follower_count < :y THEN 0 - WHEN (now()::date - aip.created_at::date) > :week - THEN greatest(1.0/:q, pow(:q, 1.0 - 1.0*(now()::date - aip.created_at::date)/:week)) * (:N * aip.week_listen_counts + :F * tp.repost_week_count + :O * tp.save_week_count + :R * tp.repost_count + :i * tp.save_count) * tp.karma + WHEN EXTRACT(DAYS from now() - aip.created_at) > :week + THEN greatest(1.0/:q, pow(:q, greatest(-10, 1.0 - 1.0*EXTRACT(DAYS from now() - aip.created_at)/:week))) * (:N * aip.week_listen_counts + :F * tp.repost_week_count + :O * tp.save_week_count + :R * tp.repost_count + :i * tp.save_count) * tp.karma ELSE (:N * aip.week_listen_counts + :F * tp.repost_week_count + :O * tp.save_week_count + :R * tp.repost_count + :i * tp.save_count) * tp.karma END as week_score, now() @@ -67,8 +67,8 @@ def update_track_score_query(self, session): CASE WHEN tp.owner_follower_count < :y THEN 0 - WHEN (now()::date - aip.created_at::date) > :month - THEN greatest(1.0/:q, pow(:q, 1.0 - 1.0*(now()::date - aip.created_at::date)/:month)) * (:N * aip.month_listen_counts + :F * tp.repost_month_count + :O * tp.save_month_count + :R * tp.repost_count + :i * tp.save_count) * tp.karma + WHEN EXTRACT(DAYS from now() - aip.created_at) > :month + THEN greatest(1.0/:q, pow(:q, greatest(-10, 1.0 - 1.0*EXTRACT(DAYS from now() - aip.created_at)/:month))) * (:N * aip.month_listen_counts + :F * tp.repost_month_count + :O * tp.save_month_count + :R * tp.repost_count + :i * tp.save_count) * tp.karma ELSE (:N * aip.month_listen_counts + :F * tp.repost_month_count + :O * tp.save_month_count + :R * tp.repost_count + :i * tp.save_count) * tp.karma END as month_score, now() @@ -86,8 +86,8 @@ def update_track_score_query(self, session): CASE WHEN tp.owner_follower_count < :y THEN 0 - WHEN (now()::date - aip.created_at::date) > :year - THEN greatest(1.0/:q, pow(:q, 1.0 - 1.0*(now()::date - aip.created_at::date)/:year)) * (:N * aip.year_listen_counts + :F * tp.repost_year_count + :O * tp.save_year_count + :R * tp.repost_count + :i * tp.save_count) * tp.karma + WHEN EXTRACT(DAYS from now() - aip.created_at) > :year + THEN greatest(1.0/:q, pow(:q, greatest(-10, 1.0 - 1.0*EXTRACT(DAYS from now() - aip.created_at)/:year))) * (:N * aip.year_listen_counts + :F * tp.repost_year_count + :O * tp.save_year_count + :R * tp.repost_count + :i * tp.save_count) * tp.karma ELSE (:N * aip.year_listen_counts + :F * tp.repost_year_count + :O * tp.save_year_count + :R * tp.repost_count + :i * tp.save_count) * tp.karma END as year_score, now()