mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 06:21:40 +00:00
ifcopenshell.api.run optimization
cache usecase classes instead of importing their modules and getting them each time, makes empty api call twice as fast
This commit is contained in:
@@ -70,6 +70,8 @@ ARGUMENTS_DEPRECATION = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CACHED_USECASE_CLASSES = dict()
|
||||||
|
|
||||||
def run(
|
def run(
|
||||||
usecase_path: str,
|
usecase_path: str,
|
||||||
ifc_file: Optional[ifcopenshell.file] = None,
|
ifc_file: Optional[ifcopenshell.file] = None,
|
||||||
@@ -108,9 +110,12 @@ def run(
|
|||||||
# except:
|
# except:
|
||||||
# print(usecase_path, vcs_settings)
|
# print(usecase_path, vcs_settings)
|
||||||
|
|
||||||
importlib.import_module(f"ifcopenshell.api.{usecase_path}")
|
usecase_class = CACHED_USECASE_CLASSES.get(usecase_path)
|
||||||
module, usecase = usecase_path.split(".")
|
if usecase_class is None:
|
||||||
usecase_class = getattr(getattr(getattr(ifcopenshell.api, module), usecase), "Usecase")
|
importlib.import_module(f"ifcopenshell.api.{usecase_path}")
|
||||||
|
module, usecase = usecase_path.split(".")
|
||||||
|
usecase_class = getattr(getattr(getattr(ifcopenshell.api, module), usecase), "Usecase")
|
||||||
|
CACHED_USECASE_CLASSES[usecase_path] = usecase_class
|
||||||
|
|
||||||
if ifc_file:
|
if ifc_file:
|
||||||
result = usecase_class(ifc_file, **settings).execute()
|
result = usecase_class(ifc_file, **settings).execute()
|
||||||
|
|||||||
Reference in New Issue
Block a user