Skip to content

Commit

Permalink
jira: Cache field data
Browse files Browse the repository at this point in the history
In order to avoid calling /field more than once per
session, override the field() call.  This is related
to (and arguably obviates):

pycontribs/jira#1798
  • Loading branch information
lhh committed Jan 18, 2024
1 parent 6de5aa7 commit 3b173ad
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions jirate/jboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ def _check_fields(issue, name):
return None


class JIRAWrapper(JIRA):
# Ensures we never call fields() twice, to save API calls

def fields(self):
if not hasattr(self, '_fields_cache_value_raw'):
self._fields_cache_value_raw = super().fields()
return self._fields_cache_value_raw


class Jirate(object):
"""High-level wrapper for python-jira"""
def __init__(self, jira):
Expand Down Expand Up @@ -856,7 +865,7 @@ def get_jira(jconfig):
jconfig: dict of 3 keys: url, token, proxies (optional)
Returns:
jira.JIRA
JIRAWrapper
"""
if 'url' not in jconfig:
print('No JIRA URL specified')
Expand All @@ -867,4 +876,4 @@ def get_jira(jconfig):
if 'proxies' not in jconfig:
jconfig['proxies'] = {"http": "", "https": ""}

return JIRA(jconfig['url'], token_auth=jconfig['token'], proxies=jconfig['proxies'])
return JIRAWrapper(jconfig['url'], token_auth=jconfig['token'], proxies=jconfig['proxies'])

0 comments on commit 3b173ad

Please sign in to comment.