Bläddra i källkod

Fix duplicate configuration call in audit logger initialization (#4232)

The get_audit_logger() function was calling
  AUDIT_LOG_MAX_FILE_SIZE.get()
  twice in the same expression when parsing file size
  configuration. This
  causes unnecessary overhead as the Config.get() method
  may involve file
  system access, locks, or other expensive operations.

  Changes:
  - Cache AUDIT_LOG_MAX_FILE_SIZE.get() result in a local
  variable
  - Use the cached value to extract both size and unit
  components
  - Improves performance by eliminating redundant
  configuration calls

Co-authored-by: Harsh Gupta <42064744+Harshg999@users.noreply.github.com>
xiearthur 2 månader sedan
förälder
incheckning
561aac1a19
1 ändrade filer med 2 tillägg och 1 borttagningar
  1. 2 1
      desktop/core/src/desktop/log/__init__.py

+ 2 - 1
desktop/core/src/desktop/log/__init__.py

@@ -83,7 +83,8 @@ def get_audit_logger():
 
   audit_logger = logging.getLogger("audit")
   if not [hclass for hclass in audit_logger.handlers if isinstance(hclass, AuditHandler)]:  # Don't add handler twice
-    size, unit = int(AUDIT_LOG_MAX_FILE_SIZE.get()[:-2]), AUDIT_LOG_MAX_FILE_SIZE.get()[-2:]
+    audit_file_size = AUDIT_LOG_MAX_FILE_SIZE.get()
+    size, unit = int(audit_file_size[:-2]), audit_file_size[-2:]
     maxBytes = size * 1024 ** (1 if unit == "KB" else 2 if unit == "MB" else 3)
 
     audit_handler = AuditHandler(AUDIT_EVENT_LOG_DIR.get(), maxBytes=maxBytes, backupCount=50)