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:


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


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 Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,592 views 17 21
Read article

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