From f552b9163513148a8b0fc44845d0c1dd1b3f6e68 Mon Sep 17 00:00:00 2001 From: zmezei Date: Thu, 6 Jul 2023 20:47:57 +0100 Subject: [PATCH] add class variable as a cache --- src/uagents/models.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/uagents/models.py b/src/uagents/models.py index 28bcd797..12d6dd3d 100644 --- a/src/uagents/models.py +++ b/src/uagents/models.py @@ -5,6 +5,8 @@ class Model(BaseModel): + _schema_no_descr = None + @staticmethod def remove_descriptions(schema: Dict[str, Dict[str, str]]): fields_with_descr = [] @@ -23,9 +25,11 @@ def remove_descriptions(schema: Dict[str, Dict[str, str]]): @classmethod def schema_no_descr(cls) -> Dict[str, Any]: - orig_schema = json.loads(cls.schema_json(indent=None, sort_keys=True)) - Model.remove_descriptions(orig_schema) - return orig_schema + if cls._schema_no_descr is None: + schema = json.loads(cls.schema_json(indent=None, sort_keys=True)) + Model.remove_descriptions(schema) + cls._schema_no_descr = schema + return cls._schema_no_descr @classmethod def schema_json_no_descr(cls) -> str: