From a491ae4592867063c85b390051e2bce92f3b6652 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Thu, 5 Feb 2026 10:51:13 -0500 Subject: [PATCH] Cache disk list to avoid multiple lsblk calls Add get_disk_list() function that caches the output of lsblk on first call. Subsequent calls return the cached value, reducing overhead when multiple functions need to iterate over disk devices. https://code.lotusguild.org/LotusGuild/proxDoc/issues/8 Co-Authored-By: Claude Opus 4.5 --- proxDoc.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/proxDoc.sh b/proxDoc.sh index c7939ac..2f4af97 100755 --- a/proxDoc.sh +++ b/proxDoc.sh @@ -13,6 +13,12 @@ readonly CMD_TIMEOUT=30 # Default timeout in seconds for external commands # Optional log file - set via environment variable PROXDOC_LOGFILE LOGFILE="${PROXDOC_LOGFILE:-}" +################### +# Cached Data +################### +# Disk list cache - populated on first use +DISK_LIST="" + ################### # Pattern Constants ################### @@ -114,6 +120,14 @@ checkIfOnHypervisor() { command -v pveversion >/dev/null 2>&1 } +# Get disk list with caching to avoid multiple lsblk calls +get_disk_list() { + if [[ -z "$DISK_LIST" ]]; then + DISK_LIST=$(lsblk -d -o name 2>/dev/null | grep -E "$DISK_DEVICE_PATTERN") + fi + echo "$DISK_LIST" +} + ################### # System Information Functions ################### @@ -155,7 +169,7 @@ get_disk_health() { if ! timeout $CMD_TIMEOUT smartctl -H "/dev/$disk"; then log_message warn "smartctl timed out or failed for /dev/$disk" fi - done < <(lsblk -d -o name | grep -E "$DISK_DEVICE_PATTERN") + done <<< "$(get_disk_list)" else log_message warn "smartctl not found. Install smartmontools for disk health monitoring" fi @@ -588,7 +602,7 @@ quick_health_check() { else echo -e "/dev/$disk: ${YELLOW}check timed out or unavailable${NC}" fi - done < <(lsblk -d -o name | grep -E "$DISK_DEVICE_PATTERN") + done <<< "$(get_disk_list)" fi # Node Exporter