Skip to content

Commit 4995605

Browse files
adehadsvermeulen
authored andcommitted
lazy load _fields, now called _fields_cache for clarity (pycontribs#1205)
1 parent 557e64f commit 4995605

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

jira/client.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,22 @@ def __init__(
537537
self._check_update_()
538538
JIRA.checked_version = True
539539

540-
self._fields = {}
540+
self._fields_cache_value: Dict[str, str] = {} # access via self._fields_cache
541+
542+
@property
543+
def _fields_cache(self) -> Dict[str, str]:
544+
"""Cached dictionary of {Field Name: Field ID}. Lazy loaded."""
545+
if not self._fields_cache_value:
546+
self._update_fields_cache()
547+
return self._fields_cache_value
548+
549+
def _update_fields_cache(self):
550+
"""Update the cache used for `self._fields_cache`."""
551+
self._fields_cache_value = {}
541552
for f in self.fields():
542553
if "clauseNames" in f:
543554
for name in f["clauseNames"]:
544-
self._fields[name] = f["id"]
555+
self._fields_cache_value[name] = f["id"]
545556

546557
@property
547558
def server_url(self) -> str:
@@ -2780,11 +2791,11 @@ def search_issues(
27802791
# this will translate JQL field names to REST API Name
27812792
# most people do know the JQL names so this will help them use the API easier
27822793
untranslate = {} # use to add friendly aliases when we get the results back
2783-
if self._fields:
2794+
if self._fields_cache:
27842795
for i, field in enumerate(fields):
2785-
if field in self._fields:
2786-
untranslate[self._fields[field]] = fields[i]
2787-
fields[i] = self._fields[field]
2796+
if field in self._fields_cache:
2797+
untranslate[self._fields_cache[field]] = fields[i]
2798+
fields[i] = self._fields_cache[field]
27882799

27892800
search_params = {
27902801
"jql": jql_str,

0 commit comments

Comments
 (0)