From 533b5aa7c8596c8e5bc4b4620a6d98ac5167aecd Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Mon, 13 Mar 2023 01:23:06 -0500 Subject: [PATCH] Fix url bug --- judge/middleware.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/judge/middleware.py b/judge/middleware.py index ccd1547..999678c 100644 --- a/judge/middleware.py +++ b/judge/middleware.py @@ -155,19 +155,19 @@ class SlowRequestMiddleware(object): logger_slow = logging.getLogger("judge.slow_request") start_time = time.time() response = self.get_response(request) - response_time = time.time() - start_time - url_name = resolve(request.path).url_name - - message = { - "url_name": url_name, - "response_time": response_time * 1000, - "profile": request.user.username, - "date": datetime.now().strftime("%Y/%m/%d"), - "url": request.build_absolute_uri(), - "method": request.method, - } - if response_time > 9: - logger_slow.info(json.dumps(message)) - if random.random() < 0.1: - logger.info(json.dumps(message)) + if response.status_code == 200: + response_time = time.time() - start_time + url_name = resolve(request.path).url_name + message = { + "url_name": url_name, + "response_time": response_time * 1000, + "profile": request.user.username, + "date": datetime.now().strftime("%Y/%m/%d"), + "url": request.build_absolute_uri(), + "method": request.method, + } + if response_time > 9: + logger_slow.info(json.dumps(message)) + if random.random() < 0.1: + logger.info(json.dumps(message)) return response