perf(usage-stats): prevent unnecessary writes when idle

- Add is_dirty flag to track if statistics have changed
- Only write stats file when data actually changes
- Add enable_usage_statistics setting in ComfyUI settings
- Skip backend requests when usage statistics is disabled
- Fix standalone mode compatibility for MetadataRegistry

Fixes #826
This commit is contained in:
Will Miao
2026-02-23 14:00:00 +08:00
parent ec76ac649b
commit 26b139884c
3 changed files with 93 additions and 24 deletions

View File

@@ -2,7 +2,7 @@
import { app } from "../../scripts/app.js";
import { api } from "../../scripts/api.js";
import { showToast } from "./utils.js";
import { getAutoPathCorrectionPreference } from "./settings.js";
import { getAutoPathCorrectionPreference, getUsageStatisticsPreference } from "./settings.js";
// Define target nodes and their widget configurations
const PATH_CORRECTION_TARGETS = [
@@ -25,6 +25,11 @@ app.registerExtension({
setup() {
// Listen for successful executions
api.addEventListener("execution_success", ({ detail }) => {
// Skip if usage statistics is disabled
if (!getUsageStatisticsPreference()) {
return;
}
if (detail && detail.prompt_id) {
this.updateUsageStats(detail.prompt_id);
}