def get(self): args = full_trending_parser.parse_args() offset = format_offset(args) limit = format_limit(args, TRENDING_LIMIT) key = self.get_cache_key() # Attempt to use the cached tracks list if args['user_id'] is not None: full_trending = get_trending(args) else: full_trending = use_redis_cache(key, TRENDING_TTL_SEC, lambda: get_trending(args)) trending = full_trending[offset:limit + offset] return success_response(trending)
def get_time_trending(cache_args, time, limit): time_params = {**cache_args, 'time':time} time_cache_key = extract_key(request_cache_path, time_params.items()) time_trending = use_redis_cache(time_cache_key, TRENDING_TTL_SEC, lambda: get_trending(time_params)) time_trending_track_ids = [{"track_id": track['track_id']} for track in time_trending] time_trending_track_ids = time_trending_track_ids[:limit] return time_trending_track_ids
def get(self, version): """Gets the top 100 trending (most popular) tracks on Audius""" trending_track_versions = trending_strategy_factory.get_versions_for_type(TrendingType.TRACKS).keys() version_list = list(filter(lambda v: v.name == version, trending_track_versions)) if not version_list: abort_bad_path_param('version', ns) args = trending_parser.parse_args() strategy = trending_strategy_factory.get_strategy(TrendingType.TRACKS, version_list[0]) trending_tracks = get_trending(args, strategy) return success_response(trending_tracks)
def get(self, version): trending_track_versions = trending_strategy_factory.get_versions_for_type( TrendingType.TRACKS).keys() version_list = list( filter(lambda v: v.name == version, trending_track_versions)) if not version_list: abort_bad_path_param("version", ns) args = trending_parser.parse_args() strategy = trending_strategy_factory.get_strategy( TrendingType.TRACKS, version_list[0]) trending_tracks = get_trending(args, strategy) return success_response(trending_tracks)
def get_time_trending(cache_args, time, limit, strategy): time_params = {**cache_args, "time": time} path = request_cache_path if strategy.version != DEFAULT_TRENDING_VERSIONS[TrendingType.TRACKS]: path += f"/{strategy.version.value}" time_cache_key = extract_key(path, time_params.items()) time_trending = use_redis_cache( time_cache_key, TRENDING_TTL_SEC, lambda: get_trending(time_params, strategy)) time_trending_track_ids = [{ "track_id": track["track_id"] } for track in time_trending] time_trending_track_ids = time_trending_track_ids[:limit] return time_trending_track_ids
def get(self): """Gets the top 100 trending (most popular) tracks on Audius""" args = trending_parser.parse_args() trending = get_trending(args) return success_response(trending)