Better logic for cleanup task. Skip gathering memory if we aren't going to log it anyway.

This commit is contained in:
SergeantPanda 2025-05-19 10:02:42 -05:00
parent eb223e1df2
commit 06b1dec2b6

View file

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