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:
Anders Kaseorg 2022-01-13 18:23:49 -08:00 committed by Tim Abbott
parent 5bb8520c82
commit 1dfddffc8d
1 changed files with 5 additions and 8 deletions

View File

@ -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):