def endpoints_hits():
    """
    :return: A JSON-list with information about every endpoint and its total number of hits (encoded in a JSON-object)
        For more information per endpoint, see :func: get_overview
    """
    with session_scope() as db_session:
        end_hits = get_endpoints_hits(db_session)
        dicts = []
        for et in end_hits:
            dicts.append({'name': et[0], 'hits': et[1]})
        return jsonify(dicts)
Example #2
0
def init_cache():
    """
    This should be added to the list of functions that are executed before the first request.
    It initializes the in-memory cache from the db
    """
    global memory_cache
    with session_scope() as db_session:
        last_req_dict = dict(get_last_requested(db_session))
        hits_dict = dict(get_endpoints_hits(db_session))
        averages_dict = dict(get_endpoint_averages(db_session))
        for rule in get_rules():
            memory_cache[rule.endpoint] = EndpointInfo(
                last_requested=last_req_dict.get(rule.endpoint),
                average_duration=averages_dict.get(rule.endpoint),
                hits=hits_dict.get(rule.endpoint),
            )