perf: lazy-import in CLI commands to speed up startup (#335)

This commit is contained in:
d3vyce
2026-07-02 22:40:48 +02:00
committed by GitHub
parent fe2c0f3eff
commit 44ba5bdd4b
3 changed files with 23 additions and 5 deletions
@@ -6,7 +6,7 @@ import typer
from rich.console import Console
from rich.table import Table
from ...fixtures import Context, LoadStrategy, load_fixtures_by_context
from ...fixtures import Context, LoadStrategy
from ...logger import get_logger
from ..config import get_db_context, get_fixtures_registry
from ..utils import async_command
@@ -71,6 +71,8 @@ async def load(
] = False,
) -> None:
"""Load fixtures into the database."""
from ...fixtures import load_fixtures_by_context
registry = get_fixtures_registry()
db_context = get_db_context()
+2 -1
View File
@@ -1,6 +1,5 @@
"""CLI utility functions."""
import asyncio
import functools
from collections.abc import Callable, Coroutine
from typing import Any, ParamSpec, TypeVar
@@ -24,6 +23,8 @@ def async_command(func: Callable[P, Coroutine[Any, Any, T]]) -> Callable[P, T]:
@functools.wraps(func)
def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
import asyncio
return asyncio.run(func(*args, **kwargs))
return wrapper