AtlassianPS / JiraPS

PowerShell module to interact with Atlassian JIRA
https://AtlassianPS.org/module/JiraPS
MIT License
325 stars 131 forks source link

Poor performance of `New-JiraIssue`/`Set-JiraIssue` when Jira instance has lots of custom fields #515

Open hmmwhatsthisdo opened 1 month ago

hmmwhatsthisdo commented 1 month ago

Description

New-JiraIssue and Set-JiraIssue perform very poorly when a Jira instance has a large quantity of custom fields. Our development instance has 630 CFs defined and calling Set-JiraIssue (with 3-5 Fields in the -Fields parameter) takes roughly 8 seconds to complete. The underlying HTTP PUT to Jira's REST API for creating the issue is only about 150ms of this.

Steps To Reproduce

  1. Configure Jira with a lot (~500) custom fields.
  2. Do one of the following. In either case, use the -Fields parameter to set a few custom fields for the given issue type.
    • Create an issue with New-JiraIssue
    • Update an existing issue with Set-JiraIssue
  3. Observe performance.

Expected behavior

Response time is relatively performant/semi-aligned with Jira web UI

Screenshots

Your Environment

JiraPS 2.14.7

Possible Solution

New-JiraIssue and Set-JiraIssue appear to be calling Get-JiraField in a loop for each KVP in -Fields. While the call to Get-JiraField contains a -Name parameter, the underlying API is unfiltered. This means that, when creating an issue and specifying 3 fields in the -Fields parameter against an instance with 500 custom fields, we end up retrieving (and parsing!) 1,500 custom field entries.

Two options seem to be available here:

hmmwhatsthisdo commented 1 month ago

Upon further inspection, Invoke-JiraIssueTransition (though I haven't tried it) appears to have a similar problem - we're calling Get-JiraField in a loop against the -Fields param contents here: https://github.com/AtlassianPS/JiraPS/blob/845495f7a1154b214210375798c2c334f58d1ae0/JiraPS/Public/Invoke-JiraIssueTransition.ps1#L150

There's not a meta endpoint for transitions, though the transitions API endpoint (when contextualized to a specific issue) should provide a map of properties available. This might be a better solve for parameters there (optionally falling back to EditMeta or the fields API)