Skip to content

Commit

Permalink
client: Cache raw field information
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lhh committed Apr 11, 2024
1 parent eb0ec90 commit 5b0fb53
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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"]
Expand Down

0 comments on commit 5b0fb53

Please sign in to comment.