Cache get_comfy_package_versions()
Some checks are pending
Python Linting / Run Ruff (push) Waiting to run
Python Linting / Run Pylint (push) Waiting to run

Mirrors the PACKAGE_VERSIONS cache in utils/install_util.py. Installed
package versions don't change over the lifetime of the process, so a
one-shot module-level cache makes /system_stats polling effectively free
instead of doing N importlib.metadata.version() lookups per call.
This commit is contained in:
ComfyUI Dev 2026-05-14 01:28:32 +00:00
parent 7ab2941420
commit 5777d757a2
2 changed files with 11 additions and 3 deletions

View File

@ -42,9 +42,12 @@ def get_required_frontend_version():
return get_required_packages_versions().get("comfyui-frontend-package", None)
COMFY_PACKAGE_VERSIONS = []
def get_comfy_package_versions():
"""List installed/required versions for every comfy* package in requirements.txt."""
out = []
if COMFY_PACKAGE_VERSIONS:
return COMFY_PACKAGE_VERSIONS.copy()
out = COMFY_PACKAGE_VERSIONS
for name, required in (get_required_packages_versions() or {}).items():
if not name.startswith("comfy"):
continue
@ -53,7 +56,7 @@ def get_comfy_package_versions():
except Exception:
installed = None
out.append({"name": name, "installed": installed, "required": required})
return out
return out.copy()
def check_comfy_packages_versions():

View File

@ -52,7 +52,10 @@ def mock_provider(mock_releases):
@pytest.fixture(autouse=True)
def clear_cache():
import utils.install_util
import app.frontend_management
utils.install_util.PACKAGE_VERSIONS = {}
app.frontend_management.COMFY_PACKAGE_VERSIONS = []
def test_get_release(mock_provider, mock_releases):
@ -277,7 +280,9 @@ def test_get_installed_templates_version():
def test_get_installed_templates_version_not_installed():
# Act
with patch("app.frontend_management.version", side_effect=Exception("Package not found")):
with patch(
"app.frontend_management.version", side_effect=Exception("Package not found")
):
version = FrontendManager.get_installed_templates_version()
# Assert