From 28f9ea8cd90f6f4d3f0e904b5550c9f044966d18 Mon Sep 17 00:00:00 2001 From: Lon Hohberger Date: Fri, 12 Jan 2024 12:30:32 -0500 Subject: [PATCH] client: Cache raw field information The field JSON from the JIRA server contains important information, such as schemas, which can be used by applications building on this library. Since it's generally preferred, whenever possible, to reduce unnecessary calls to JIRA API endpoints, we can keep this information in the client object. --- jira/client.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/jira/client.py b/jira/client.py index ff311bcd6..ab08c1cae 100644 --- a/jira/client.py +++ b/jira/client.py @@ -672,6 +672,14 @@ def __init__( JIRA.checked_version = True self._fields_cache_value: dict[str, str] = {} # access via self._fields_cache + self._fields_cache_value_raw: list[dict[str, Any]] = [] # access via self._fields_cache_raw + + @property + def _fields_cache_raw(self) -> list[dict[str, Any]]: + """Cached raw dictionary of of /field endpoint. Lazy loaded.""" + if not self._fields_cache_value_raw: + self._fields_cache_value_raw = self.fields() + return self._fields_cache_value_raw @property def _fields_cache(self) -> dict[str, str]: @@ -683,7 +691,7 @@ def _fields_cache(self) -> dict[str, str]: def _update_fields_cache(self): """Update the cache used for `self._fields_cache`.""" self._fields_cache_value = {} - for f in self.fields(): + for f in self._fields_cache_raw: if "clauseNames" in f: for name in f["clauseNames"]: self._fields_cache_value[name] = f["id"]