Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lazy load _fields, (now called _fields_cache for clarity) #1205

Merged
merged 1 commit into from
Oct 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,11 +537,22 @@ def __init__(
self._check_update_()
JIRA.checked_version = True

self._fields = {}
self._fields_cache_value: Dict[str, str] = {} # access via self._fields_cache

@property
def _fields_cache(self) -> Dict[str, str]:
"""Cached dictionary of {Field Name: Field ID}. Lazy loaded."""
if not self._fields_cache_value:
self._update_fields_cache()
return self._fields_cache_value

def _update_fields_cache(self):
"""Update the cache used for `self._fields_cache`."""
self._fields_cache_value = {}
for f in self.fields():
if "clauseNames" in f:
for name in f["clauseNames"]:
self._fields[name] = f["id"]
self._fields_cache_value[name] = f["id"]

@property
def server_url(self) -> str:
Expand Down Expand Up @@ -2780,11 +2791,11 @@ def search_issues(
# this will translate JQL field names to REST API Name
# most people do know the JQL names so this will help them use the API easier
untranslate = {} # use to add friendly aliases when we get the results back
if self._fields:
if self._fields_cache:
for i, field in enumerate(fields):
if field in self._fields:
untranslate[self._fields[field]] = fields[i]
fields[i] = self._fields[field]
if field in self._fields_cache:
untranslate[self._fields_cache[field]] = fields[i]
fields[i] = self._fields_cache[field]

search_params = {
"jql": jql_str,
Expand Down