From 308a8d5c5c06a7d020cdf92ed336ef525b12ea38 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Tue, 10 Feb 2026 13:00:25 -0500 Subject: [PATCH] Cache drive details to eliminate redundant smartctl calls Add per-run cache for _get_drive_details() results. Each drive is queried once via smartctl -i and the result is reused across SMART health checks and ticket creation. Resolves https://code.lotusguild.org/LotusGuild/hwmonDaemon/issues/15 Co-Authored-By: Claude Opus 4.6 --- hwmonDaemon.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hwmonDaemon.py b/hwmonDaemon.py index 1b62af9..bd30e19 100644 --- a/hwmonDaemon.py +++ b/hwmonDaemon.py @@ -665,6 +665,9 @@ class SystemHealthMonitor: # Ensure history directory exists os.makedirs(self.CONFIG['HISTORY_DIR'], exist_ok=True) + # Drive details cache (per-run, cleared on next execution) + self._drive_details_cache = {} + def _enforce_storage_limit(self, history_dir: str, max_bytes: int = None): """ Delete oldest history files if directory exceeds size limit. @@ -1072,7 +1075,10 @@ class SystemHealthMonitor: # DRIVE HEALTH CHECKING METHODS # ============================================================================= def _get_drive_details(self, device: str) -> Dict[str, str]: - """Get detailed drive information using smartctl.""" + """Get detailed drive information using smartctl (cached per run).""" + if device in self._drive_details_cache: + return self._drive_details_cache[device] + drive_details = { 'model': None, 'serial': None, @@ -1126,7 +1132,8 @@ class SystemHealthMonitor: except Exception as e: logger.debug(f"Error getting drive details for {device}: {e}") - + + self._drive_details_cache[device] = drive_details return drive_details