首页 文章

为什么调度方法需要很长时间才能在Django Rest Framework中调用目标方法?

提问于
浏览
0

我有这个方法

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())
        .....
        ......

现在,一旦我得到了两个时间,我就差不多这个时间,差异时间大约是30毫秒,你能解释一下为什么这花了这么多时间,因为登录请求需要大约0毫秒,但对于其他请求从调度方法到达目标方法需要很长时间,请帮帮我,谢谢

1 回答

  • 0

    我遇到了瓶颈,它是APIView的内部调度方法,它调用了大约30ms的“perform_authentication”方法,

    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
    

相关问题