Skip to content

Commit

Permalink
add class variable as a cache
Browse files Browse the repository at this point in the history
  • Loading branch information
zmezei committed Jul 6, 2023
1 parent 069d70c commit f552b91
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/uagents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@


class Model(BaseModel):
_schema_no_descr = None

@staticmethod
def remove_descriptions(schema: Dict[str, Dict[str, str]]):
fields_with_descr = []
Expand All @@ -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:
Expand Down

0 comments on commit f552b91

Please sign in to comment.