Skip to content

Commit 4eda814

Browse files
authored
Cache result of get_metaschema (#570)
1 parent 13f6da9 commit 4eda814

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

schema_salad/schema.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,15 @@
8181

8282
saladp = "https://w3id.org/cwl/salad#"
8383

84+
cached_metaschema: Optional[Tuple[Names, List[Dict[str, str]], Loader]] = None
85+
8486

8587
def get_metaschema() -> Tuple[Names, List[Dict[str, str]], Loader]:
8688
"""Instantiate the metaschema."""
89+
global cached_metaschema
90+
if cached_metaschema is not None:
91+
return cached_metaschema
92+
8793
loader = ref_resolver.Loader(
8894
{
8995
"Any": saladp + "Any",
@@ -199,7 +205,8 @@ def get_metaschema() -> Tuple[Names, List[Dict[str, str]], Loader]:
199205
_logger.error("Metaschema error, avro was:\n%s", json_dumps(sch_obj, indent=4))
200206
raise
201207
validate_doc(sch_names, j2, loader, strict=True)
202-
return (sch_names, j2, loader)
208+
cached_metaschema = (sch_names, j2, loader)
209+
return cached_metaschema
203210

204211

205212
def add_namespaces(

0 commit comments

Comments
 (0)