Best way to get Issue Count by Component

We have a number of duplicate components in our project and some that are just named incorrectly, so I wrote a program to fix these issues.

The problem is I don't want to delete a component if it's associated with Issues. I want to move it to a different component, which I do using the appropriate API call.

To find out if a component is being used by any issues I call the following to get all components for our project:

/rest/api/latest/project/{key}/components

I would then loop through those components and call the following to get all related issues for each component:

/rest/api/latest/component/{id}/relatedIssueCounts

However, this is incredibly slow and it makes a lot of calls to the REST API. 165+, so far.

It would be nice if the call to return all components for a project could include the relatedIssueCount as a JSON property. Maybe it does, but I didn't see it.

Anyhow, is there a better way to do it than I'm currently doing it? 

1 answer

Since you probably know which components you wan to process, I would attempt to search for issues with those components using JQL through the REST API /rest/api/2/search.

 

Thanks. I tried what you suggested, but it takes just as long. I guess there's no better way. They really need to just change the /rest/api/latest/project/{key}/components JSON to include the relatedIssueCounts.

How many issues do you have? It really should not be that slow. I am assuming you are using maxresults and startwith parameters so you can get back a large set of issues.

I would also turn off validate JQL as well.

Maybe your real issue is the JIRA Cloud. Does the JQL run slowly through the JIRA UI?

It's not really about issues per say since the only thing I query concerning issues is a count per component using /rest/api/latest/component/{id}/relatedIssueCounts. We have around 165 components and querying those using /rest/api/latest/project/{key}/components takes about 1.5-2 seconds. Looping through those 165 components to determine if they are assigned to issues takes just shy of a minute. It's not horrible, but if the /rest/api/latest/project/{key}/components call already returned that data then I suspect the total cal would be no more than 5 seconds. The cloud searches run fine, but there's really no way to determine what I want in the cloud search. Anyways, it's no big deal that it takes around a minute total to get the data. I was just hoping the /rest/api/latest/project/{key}/components call returned more info/data so my code would be more efficient.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,777 views 11 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot