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

Unnecessary api call to /rest/api/2/field #1859

Open
2 of 4 tasks
aneeshco opened this issue May 2, 2024 · 2 comments
Open
2 of 4 tasks

Unnecessary api call to /rest/api/2/field #1859

aneeshco opened this issue May 2, 2024 · 2 comments
Labels
enhancement good first issue New contributors welcome !

Comments

@aneeshco
Copy link

aneeshco commented May 2, 2024

Bug summary

When doing api call using search_issues, it makes two API calls, one GET to the endpoint /rest/api/2/field and another to the actual url /rest/api/2/search. The first api call, returns the whole fields present in the JIRA server environment causing performance issues in the server. This is only done once the first time the function is used. Can this function be updated so that only the /rest/api/2/search is accessed?

issues_page = jira.search_issues(
jql_query,
startAt=start_at,
maxResults=MAX_RESULTS,
validate_query=False,
fields=fields_arg,
expand=None,
properties=None,
use_post=True)

Is there an existing issue for this?

  • I have searched the existing issues

Jira Instance type

Jira Server or Data Center (Self-hosted)

Jira instance version

9.4.6

jira-python version

3.8

Python Interpreter version

3.11.5

Which operating systems have you used?

  • Linux
  • macOS
  • Windows

Reproduction steps

# 1. Given a Jira client instance
jira: JIRA
# 2. When I call the function with below arguments 
issues_page = jira.search_issues(
                jql_query, 
                startAt=start_at, 
                maxResults=MAX_RESULTS,
                validate_query=False,
                fields=fields_arg,
                expand=None,
                properties=None,
                use_post=True)
# 3. It first calls the field endpoint and then it calls the search endpoint the first time, subsequent times doesnot include calls to field endpoint
# 4. It should only call the search endpoint and not the field endpoint
...

Stack trace

The order of api calls as below when

/rest/api/2/serverInfo - authentication
/rest/api/2/field -  first call to search_issues function
/rest/api/2/search - first call to search_issues function
/rest/api/2/search - second call to search_issues function
/rest/api/2/search - third call to search_issues function
/rest/api/2/search - fourth call to search_issues function

Expected behaviour

Expected behaviour as below
/rest/api/2/serverInfo - authentication
/rest/api/2/search - first call to search_issues function
/rest/api/2/search - second call to search_issues function
/rest/api/2/search - third call to search_issues function
/rest/api/2/search - fourth call to search_issues function

Additional Context

None

@adehad
Copy link
Contributor

adehad commented Jul 9, 2024

@aneeshco I might suggest subclassing the main Jira class with your own implementation, some of the features of this library are aimed at user convenience rather than pure performance.

There is something I can see regarding the default case for all fields, and this is an opportunity for improvement, where if all the fields are requested, then no API call to fields is necessary. I will therefore leave this issue open with that resolution being the required fix

@adehad adehad added enhancement good first issue New contributors welcome ! labels Jul 9, 2024
@avatarofhope2
Copy link

avatarofhope2 commented Aug 1, 2024

I currently store this information separately, and set it manually using this:

def update_fields_cache(self, jira_client):
    if self.fields is None:
        self.fields = {}
        fields = self.db.get_jira_fields()
        for field in fields:
            self.fields[field['id']] = field['name']
    for field in self.fields:
        # this imitates jira client lazy loading of fields from API (jira.client.JIRA._fields_cache)
        if "clauseNames" in field:
            clause_names = field["clauseNames"].split('|')
            for name in clause_names:
                jira_client._fields_cache_value[name] = field["id"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement good first issue New contributors welcome !
Projects
None yet
Development

No branches or pull requests

3 participants