refactor: implement lazy loading for coordinator-api service imports
All checks were successful
All checks were successful
Replaced eager imports with lazy loading using __getattr__ to defer service module imports until first access. Added module mapping dictionary and dynamic import logic to reduce initial import overhead while maintaining the same public API.
This commit is contained in:
@@ -1,8 +1,23 @@
|
||||
"""Service layer for coordinator business logic."""
|
||||
|
||||
from .explorer import ExplorerService
|
||||
from .jobs import JobService
|
||||
from .marketplace import MarketplaceService
|
||||
from .miners import MinerService
|
||||
from importlib import import_module
|
||||
|
||||
__all__ = ["JobService", "MinerService", "MarketplaceService", "ExplorerService"]
|
||||
|
||||
_MODULE_BY_EXPORT = {
|
||||
"ExplorerService": ".explorer",
|
||||
"JobService": ".jobs",
|
||||
"MarketplaceService": ".marketplace",
|
||||
"MinerService": ".miners",
|
||||
}
|
||||
|
||||
|
||||
def __getattr__(name: str):
|
||||
module_name = _MODULE_BY_EXPORT.get(name)
|
||||
if module_name is None:
|
||||
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
||||
|
||||
module = import_module(module_name, __name__)
|
||||
value = getattr(module, name)
|
||||
globals()[name] = value
|
||||
return value
|
||||
|
||||
Reference in New Issue
Block a user