(get_response)
return middleware
Prints the time needed to perform a request.
Prints the time needed to perform a request.
Prints the time needed to perform a request .
def benchmark(get_response):
    """
    Prints the time needed to perform a request.
    """

    def middleware(request):

        # Start timer.
        start = time.time()

        # Performs the request
        response = get_response(request)

        # Elapsed time.
        delta = int((time.time() - start) * 1000)

        # Generate timing message.
        msg = f'time={delta}ms for path={request.path}'

        if delta > 1000:
            ip = helpers.get_ip(request)
            uid = request.user.profile.uid if request.user.is_authenticated else '0'
            #agent = request.META.get('HTTP_USER_AGENT', None)
            logger.warning(f"SLOW: {msg} IP:{ip} uid:{uid}")
        elif settings.DEBUG:
            logger.info(f'{msg}')

        return response

    return middleware
def benchmark ( get_response ) : def middleware ( request ) : # Start timer. start = time . time ( ) # Performs the request response = get_response ( request ) # Elapsed time. delta = int ( ( time . time ( ) - start ) * 1000 ) # Generate timing message. msg = f'time={delta}ms for path={request.path}' if delta > 1000 : ip = helpers . get_ip ( request ) uid = request . user . profile . uid if request . user . is_authenticated else '0' #agent = request.META.get('HTTP_USER_AGENT', None) logger . warning ( f"SLOW: {msg} IP:{ip} uid:{uid}" ) elif settings . DEBUG : logger . info ( f'{msg}' ) return response return middleware