fix: keep disabled unused packages manageable

This commit is contained in:
Ethanfel
2026-07-29 20:00:23 +02:00
parent 6d433ba371
commit 228542c71a
5 changed files with 100 additions and 17 deletions
+31 -5
View File
@@ -217,8 +217,14 @@ class UsageTracker:
finally:
conn.close()
def get_package_stats(self, mapper):
"""Aggregate per-package stats combining DB data with known nodes."""
def get_package_stats(self, mapper, disabled_packages=()):
"""Aggregate package stats from usage, active nodes, and disabled packs.
``disabled_packages`` is the set of directory names currently parked in
``custom_nodes/.disabled``. Those packages are no longer loaded, so
they cannot appear in the node mapper. Including them here keeps a
never-used package visible long enough for the UI to offer Enable.
"""
node_stats = self.get_node_stats()
# Build per-package data from DB
@@ -263,13 +269,33 @@ class UsageTracker:
}
packages[pkg]["total_nodes"] = total
# Packages only in DB (not in mapper) are uninstalled/disabled
# Packages only in DB (not in mapper) are uninstalled/disabled.
# Also add disabled-on-disk packages that have no recorded executions;
# without this, a package disabled before first use disappears from the
# UI and cannot be re-enabled there.
active_package_keys = {pkg.lower() for pkg in node_counts}
existing_package_keys = {pkg.lower() for pkg in packages}
for pkg in disabled_packages:
if not isinstance(pkg, str) or not pkg or pkg.lower() in active_package_keys:
continue
if pkg.lower() in existing_package_keys:
continue
packages[pkg] = {
"package": pkg,
"total_executions": 0,
"used_nodes": 0,
"nodes": [],
"last_seen": None,
"total_nodes": 0,
}
existing_package_keys.add(pkg.lower())
# node_counts already includes all packages from mapper + get_all_packages()
installed_packages = set(node_counts.keys())
installed_packages = active_package_keys
for pkg, entry in packages.items():
if "total_nodes" not in entry:
entry["total_nodes"] = entry["used_nodes"]
entry["installed"] = pkg in installed_packages
entry["installed"] = pkg.lower() in installed_packages
# Classify packages by usage recency
now = datetime.now(timezone.utc)