1
votes

I have this method

class RunningQuizAuthenticationView(APIView):

    def dispatch(self, *args, **kwargs):
        print(time.time())
        return super(RunningQuizAuthenticationView, self).dispatch(*args, **kwargs)

    def get(self, request: Request, key: str) -> Response:
        print(time.time())
        .....
        ......

Now, once I get both the time, I take the difference of this time, the difference time is about 30 ms, can you explain to me why this is taking so much time, for the login request it takes about 0 ms but for other requests it takes a long time to reach target method from dispatch method, please help me, Thank you

1
You don't say where you get the time difference and what they are supposed to be. Can you be more specific ? time.time() will just display a time... - Linovia
Once time gets printed on the console, I take it and take the difference using a calculator. As we know dispatch is the method which calls our target method. - Vicky Gupta
What operations are there in your other views? I/O examples please. - Sachin
30 ms is not a long time! It is 0.03 second. How fast do you want it to be? - Jahongir Rahmonov
Finally, I got the bottleneck, It is inside dispatch method of APIView, it calls "perform_authentication" method which is taking about 30ms, I will solve it now, Thank you guys for your responses :) - Vicky Gupta

1 Answers

0
votes

I got the bottleneck, It is inside dispatch method of APIView, it calls "perform_authentication" method which is taking about 30ms,

def perform_authentication(self, request):
        """
        Perform authentication on the incoming request.

    Note that if you override this and simply 'pass', then authentication
    will instead be performed lazily, the first time either
    `request.user` or `request.auth` is accessed.
    """
    request.user