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

Improve performance of New-/Set-JiraIssue on instances with large quantities of fields #516

Merged

Conversation

hmmwhatsthisdo
Copy link
Contributor

@hmmwhatsthisdo hmmwhatsthisdo commented Aug 8, 2024

Description

This PR adjusts the functionality of New-JiraIssue and Set-JiraIssue to only call Get-JiraField once (if -Fields is set) instead of once per entry in the -Fields hashtable.

Additionally, both cmdlets will resolve numerical IDs for custom fields if users specify fields in that way (i.e. -Fields @{12345 = $foo} is equivalent to -Fields @{customfield_12345 = $foo})

Motivation and Context

Get-JiraField takes a -Name parameter, however the underlying API call is not filtered by name. This means that every field in the instance (visible to the current user) is retrieved for each key in -Fields. This means network traffic/CPU usage/time spent scales quadratically in practice (linear to the number of CFs in the API call and the number of CFs in the instance).

By moving Get-JiraField out of this loop (thus only calling it once), we can cache field data instead of hammering Jira's API for it.

Closes #515.

Improvement Areas

We currently query the whole instance's fields which, on larger (or poorly-organized) instances, may:

  • Be very large
  • Include duplicate fields used in different contexts than the user's

Using the CreateMeta and EditMeta endpoints (with Get-JiraIssueCreateMetadata and Get-JiraIssueEditMetadata) would reduce response size and limit fields to ones that are actually relevant to the current project/issue context.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • I have added Pester Tests that describe what my changes should do.
  • I have updated the documentation accordingly.

@hmmwhatsthisdo hmmwhatsthisdo requested a review from a team as a code owner August 8, 2024 02:59
@hmmwhatsthisdo hmmwhatsthisdo changed the base branch from release/2.15-alpha to develop August 8, 2024 03:12
@lipkau lipkau changed the base branch from develop to release/2.15-alpha August 11, 2024 10:49
Copy link
Member

@lipkau lipkau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix tests

@hmmwhatsthisdo
Copy link
Contributor Author

Fix tests

Will do, I'll give it a look this evening. Thanks for approving the CI pass!

@hmmwhatsthisdo
Copy link
Contributor Author

@lipkau Dug into this a bit - the problem appears to be that the unit tests use a mock for Get-JiraField that only supports the field-specific implementation. New-JiraIssue appears to be easy to fix, but Set-JiraIssue might need more nuance to it.

(As an aside, it would be in our best interest to upgrade to Pester 5)

@hmmwhatsthisdo
Copy link
Contributor Author

hmmwhatsthisdo commented Aug 13, 2024

@lipkau Unit tests should be green again. Can you click the "Approve and run" button to re-approve running test workflows?

@lipkau
Copy link
Member

lipkau commented Aug 13, 2024

shall we document something about further refactoring in this area?

@hmmwhatsthisdo
Copy link
Contributor Author

hmmwhatsthisdo commented Aug 13, 2024

shall we document something about further refactoring in this area?

@lipkau When I'm back at my desk, I can cut an issue for:

Anything else you see as being necessary here?

@hmmwhatsthisdo
Copy link
Contributor Author

@lipkau Issues have been filed. Can you merge the PR when you have a moment?

@lipkau lipkau merged commit 3d2afbe into AtlassianPS:release/2.15-alpha Aug 14, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants