mirror of https://github.com/zulip/zulip.git
profile_request: Use modern Django middleware API.
Fixes “RemovedInDjango40Warning: Passing None for the middleware get_response argument is deprecated.” from LogRequests(). Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
5bb8520c82
commit
1dfddffc8d
|
@ -14,8 +14,6 @@ from zerver.middleware import LogRequests
|
|||
from zerver.models import UserMessage
|
||||
from zerver.views.message_fetch import get_messages_backend
|
||||
|
||||
request_logger = LogRequests()
|
||||
|
||||
|
||||
class MockSession(SessionBase):
|
||||
def __init__(self) -> None:
|
||||
|
@ -23,16 +21,15 @@ class MockSession(SessionBase):
|
|||
|
||||
|
||||
def profile_request(request: HttpRequest) -> HttpResponse:
|
||||
request_logger.process_request(request)
|
||||
def get_response(request: HttpRequest) -> HttpResponse:
|
||||
return prof.runcall(get_messages_backend, request, request.user, apply_markdown=True)
|
||||
|
||||
prof = cProfile.Profile()
|
||||
prof.enable()
|
||||
ret = get_messages_backend(request, request.user, apply_markdown=True)
|
||||
prof.disable()
|
||||
with tempfile.NamedTemporaryFile(prefix="profile.data.", delete=False) as stats_file:
|
||||
response = LogRequests(get_response)(request)
|
||||
prof.dump_stats(stats_file.name)
|
||||
request_logger.process_response(request, ret)
|
||||
logging.info("Profiling data written to %s", stats_file.name)
|
||||
return ret
|
||||
return response
|
||||
|
||||
|
||||
class Command(ZulipBaseCommand):
|
||||
|
|
Loading…
Reference in New Issue