Fix url bug

This commit is contained in:
cuom1999 2023-03-13 01:23:06 -05:00
parent 580a4019c7
commit 533b5aa7c8

View file

@ -155,19 +155,19 @@ class SlowRequestMiddleware(object):
logger_slow = logging.getLogger("judge.slow_request") logger_slow = logging.getLogger("judge.slow_request")
start_time = time.time() start_time = time.time()
response = self.get_response(request) response = self.get_response(request)
response_time = time.time() - start_time if response.status_code == 200:
url_name = resolve(request.path).url_name response_time = time.time() - start_time
url_name = resolve(request.path).url_name
message = { message = {
"url_name": url_name, "url_name": url_name,
"response_time": response_time * 1000, "response_time": response_time * 1000,
"profile": request.user.username, "profile": request.user.username,
"date": datetime.now().strftime("%Y/%m/%d"), "date": datetime.now().strftime("%Y/%m/%d"),
"url": request.build_absolute_uri(), "url": request.build_absolute_uri(),
"method": request.method, "method": request.method,
} }
if response_time > 9: if response_time > 9:
logger_slow.info(json.dumps(message)) logger_slow.info(json.dumps(message))
if random.random() < 0.1: if random.random() < 0.1:
logger.info(json.dumps(message)) logger.info(json.dumps(message))
return response return response