perf: 添加 sql debug

pull/10800/head
ibuler 2023-06-21 11:47:53 +08:00 committed by Jiangjie.Bai
parent b9c1a89f51
commit fa24a8e2f3
2 changed files with 14 additions and 0 deletions

View File

@ -101,6 +101,19 @@ class RefererCheckMiddleware:
return response
class SQLCountMiddleware:
def __init__(self, get_response):
self.get_response = get_response
if not settings.DEBUG_DEV:
raise MiddlewareNotUsed
def __call__(self, request):
from django.db import connection
response = self.get_response(request)
response['X-JMS-SQL-COUNT'] = len(connection.queries)
return response
class StartMiddleware:
def __init__(self, get_response):
self.get_response = get_response

View File

@ -128,6 +128,7 @@ MIDDLEWARE = [
'jumpserver.middleware.DemoMiddleware',
'jumpserver.middleware.RequestMiddleware',
'jumpserver.middleware.RefererCheckMiddleware',
'jumpserver.middleware.SQLCountMiddleware',
'orgs.middleware.OrgMiddleware',
'authentication.backends.oidc.middleware.OIDCRefreshIDTokenMiddleware',
'authentication.backends.cas.middleware.CASMiddleware',