From 06b1dec2b60ffeb2d54b5a45a86091376769fa4e Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Mon, 19 May 2025 10:02:42 -0500 Subject: [PATCH] Better logic for cleanup task. Skip gathering memory if we aren't going to log it anyway. --- core/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/utils.py b/core/utils.py index 1dabf3a6..d26b0dd3 100644 --- a/core/utils.py +++ b/core/utils.py @@ -254,7 +254,10 @@ def cleanup_memory(log_usage=True, force_collection=True): log_usage: Whether to log memory usage before and after cleanup force_collection: Whether to force garbage collection """ - logger.debug("Starting memory cleanup django memory cleanup") + logger.trace("Starting memory cleanup django memory cleanup") + # Skip logging if log level is not set to debug (no reason to run memory usage if we don't log it) + if not logger.isEnabledFor(logging.DEBUG): + log_usage = False if log_usage: try: import psutil @@ -283,4 +286,4 @@ def cleanup_memory(log_usage=True, force_collection=True): logger.debug(f"Memory after cleanup: {after_mem:.2f} MB (change: {after_mem-before_mem:.2f} MB)") except (ImportError, Exception): pass - logger.debug("Memory cleanup complete for django") + logger.trace("Memory cleanup complete for django")