CLI Speed improvements. (#23189)

This commit is contained in:
Nick Brassel 2024-03-02 08:45:01 +11:00 committed by GitHub
parent 8b8f73098b
commit 1875659df0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,6 +7,7 @@ from collections.abc import Mapping
from functools import lru_cache from functools import lru_cache
from typing import OrderedDict from typing import OrderedDict
from pathlib import Path from pathlib import Path
from copy import deepcopy
from milc import cli from milc import cli
@ -22,7 +23,8 @@ def _dict_raise_on_duplicates(ordered_pairs):
return d return d
def json_load(json_file, strict=True): @lru_cache(maxsize=20)
def _json_load_impl(json_file, strict=True):
"""Load a json file from disk. """Load a json file from disk.
Note: file must be a Path object. Note: file must be a Path object.
@ -42,7 +44,11 @@ def json_load(json_file, strict=True):
exit(1) exit(1)
@lru_cache(maxsize=0) def json_load(json_file, strict=True):
return deepcopy(_json_load_impl(json_file=json_file, strict=strict))
@lru_cache(maxsize=20)
def load_jsonschema(schema_name): def load_jsonschema(schema_name):
"""Read a jsonschema file from disk. """Read a jsonschema file from disk.
""" """
@ -57,7 +63,7 @@ def load_jsonschema(schema_name):
return json_load(schema_path) return json_load(schema_path)
@lru_cache(maxsize=0) @lru_cache(maxsize=1)
def compile_schema_store(): def compile_schema_store():
"""Compile all our schemas into a schema store. """Compile all our schemas into a schema store.
""" """
@ -73,7 +79,7 @@ def compile_schema_store():
return schema_store return schema_store
@lru_cache(maxsize=0) @lru_cache(maxsize=20)
def create_validator(schema): def create_validator(schema):
"""Creates a validator for the given schema id. """Creates a validator for the given schema id.
""" """