From fcca25397cb002e1755ee0fff261ca4be53caa54 Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Sun, 22 Feb 2026 13:50:11 +0100 Subject: [PATCH] Move DB writes to background thread and add SVG icon Record usage in a daemon thread to avoid blocking the event loop with SQLite fsync on slow storage. Replace text button label with a bar-chart-with-nodes SVG icon in the legacy menu fallback. Co-Authored-By: Claude Opus 4.6 --- __init__.py | 7 ++++++- js/nodes_stats.js | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index 4517963..4847872 100644 --- a/__init__.py +++ b/__init__.py @@ -1,4 +1,5 @@ import logging +import threading from aiohttp import web from server import PromptServer @@ -25,7 +26,11 @@ def on_prompt_handler(json_data): if ct: class_types.add(ct) if class_types: - tracker.record_usage(class_types, mapper) + threading.Thread( + target=tracker.record_usage, + args=(class_types, mapper), + daemon=True, + ).start() except Exception: logger.warning("nodes-stats: error recording usage", exc_info=True) return json_data diff --git a/js/nodes_stats.js b/js/nodes_stats.js index da60b00..169e57b 100644 --- a/js/nodes_stats.js +++ b/js/nodes_stats.js @@ -1,5 +1,15 @@ import { app } from "../../scripts/app.js"; +// Bar chart with nodes icon +const STATS_ICON = ` + + + + + + +`; + app.registerExtension({ name: "comfyui.nodes_stats", @@ -25,8 +35,11 @@ app.registerExtension({ ); const btn = document.createElement("button"); - btn.textContent = "Node Stats"; + btn.innerHTML = STATS_ICON; + btn.title = "Node Stats"; btn.onclick = () => showStatsDialog(); + btn.style.cssText = + "display:flex;align-items:center;justify-content:center;padding:6px;background:none;border:none;cursor:pointer;color:var(--input-text,#ddd);"; const menu = document.querySelector(".comfy-menu"); if (menu) {