Exemple #1
0
def get_top_followee_saves_route(type):
    """
    Gets a global view into the most saved of `type` amongst followees. Requires an account.
    This endpoint is useful in generating views like:
        - Most favorited

    Args:
        type: (string) The `type` (same as repost/save type) to query from. Currently only
            track is supported.
        limit?: (number) default=25, max=100
    """
    args = to_dict(request.args)
    if "limit" in request.args:
        args["limit"] = min(request.args.get("limit", type=int), 100)
    else:
        args["limit"] = 25
    if "with_users" in request.args:
        args["with_users"] = parse_bool_param(request.args.get("with_users"))
    user_id = get_current_user_id()
    args["user_id"] = user_id
    try:
        tracks = get_top_followee_saves(type, args)
        return api_helpers.success_response(tracks)
    except exceptions.ArgumentError as e:
        return api_helpers.error_response(str(e), 400)
Exemple #2
0
def ipld_block_check():
    use_redis_cache = parse_bool_param(request.args.get("use_cache"))
    latest_ipld_indexed_block, latest_indexed_ipld_block_hash = get_latest_ipld_indexed_block(use_redis_cache)

    return success_response(
        {"db":{"number": latest_ipld_indexed_block, "blockhash": latest_indexed_ipld_block_hash}}
    )
Exemple #3
0
def search(isAutocomplete):
    searchStr = request.args.get("query", type=str)
    if not searchStr:
        raise exceptions.ArgumentError("Invalid value for parameter 'query'")
    searchStr = searchStr.replace('&', 'and')  # when creating query table, we substitute this too

    (limit, offset) = get_pagination_vars()

    results = {
        'tracks': [],
        'users': [],
        'playlists': [],
        'albums': [],
        'saved_tracks': [],
        'followed_users': [],
        'saved_playlists': [],
        'saved_albums': [],
    }

    if searchStr:
        db = get_db()
        with db.scoped_session() as session:
            results['tracks'] = track_search_query(session, searchStr, limit, offset, False, isAutocomplete)
            results['users'] = user_search_query(session, searchStr, limit, offset, False, isAutocomplete)
            results['playlists'] = playlist_search_query(
                session,
                searchStr,
                limit,
                offset,
                False,
                False,
                isAutocomplete
            )
            results['albums'] = playlist_search_query(session, searchStr, limit, offset, True, False, isAutocomplete)

            results['saved_tracks'] = track_search_query(session, searchStr, limit, offset, True, isAutocomplete)
            results['followed_users'] = user_search_query(session, searchStr, limit, offset, True, isAutocomplete)
            results['saved_playlists'] = playlist_search_query(
                session,
                searchStr,
                limit,
                offset,
                False,
                True,
                isAutocomplete
            )
            results['saved_albums'] = playlist_search_query(
                session,
                searchStr,
                limit,
                offset,
                True,
                True,
                isAutocomplete
            )

    return api_helpers.success_response(results)
Exemple #4
0
def user_signals():
    handle = request.args.get("handle")
    if not handle:
        return error_response("Please pass in a handle")
    try:
        response = get_user_signals(handle)
        return success_response(response)
    except Exception as e:
        return error_response(f"Request failed: {e}")
def index_block_stats():
    redis = redis_connection.get_redis()

    results = {
        "index_blocks_ms": {
            "minute":
            get_index_blocks_ms_stats_since(redis, MINUTE_IN_SECONDS),
            "ten_minutes":
            get_index_blocks_ms_stats_since(redis, TEN_MINUTES_IN_SECONDS),
            "hour":
            get_index_blocks_ms_stats_since(redis, HOUR_IN_SECONDS),
            "six_hour":
            get_index_blocks_ms_stats_since(redis, SIX_HOURS_IN_SECONDS),
            "twelve_hour":
            get_index_blocks_ms_stats_since(redis, TWELVE_HOURS_IN_SECONDS),
            "day":
            get_index_blocks_ms_stats_since(redis, DAY_IN_SECONDS),
        },
        "fetch_ipfs_metadata_ms": {
            "minute":
            get_fetch_ipfs_metadata_ms_stats_since(redis, MINUTE_IN_SECONDS),
            "ten_minutes":
            get_fetch_ipfs_metadata_ms_stats_since(redis,
                                                   TEN_MINUTES_IN_SECONDS),
            "hour":
            get_fetch_ipfs_metadata_ms_stats_since(redis, HOUR_IN_SECONDS),
            "six_hour":
            get_fetch_ipfs_metadata_ms_stats_since(redis,
                                                   SIX_HOURS_IN_SECONDS),
            "twelve_hour":
            get_fetch_ipfs_metadata_ms_stats_since(redis,
                                                   TWELVE_HOURS_IN_SECONDS),
            "day":
            get_fetch_ipfs_metadata_ms_stats_since(redis, DAY_IN_SECONDS),
        },
        "add_indexed_block_to_db_ms": {
            "minute":
            get_add_indexed_block_to_db_ms_stats_since(redis,
                                                       MINUTE_IN_SECONDS),
            "ten_minutes":
            get_add_indexed_block_to_db_ms_stats_since(redis,
                                                       TEN_MINUTES_IN_SECONDS),
            "hour":
            get_add_indexed_block_to_db_ms_stats_since(redis, HOUR_IN_SECONDS),
            "six_hour":
            get_add_indexed_block_to_db_ms_stats_since(redis,
                                                       SIX_HOURS_IN_SECONDS),
            "twelve_hour":
            get_add_indexed_block_to_db_ms_stats_since(
                redis, TWELVE_HOURS_IN_SECONDS),
            "day":
            get_add_indexed_block_to_db_ms_stats_since(redis, DAY_IN_SECONDS),
        },
    }

    return success_response(results, sign_response=False)