Best way to get Issue Count by Component

Chris Tietgen December 4, 2014

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

0 votes
Norman Abramovitz
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 4, 2014

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.

 

Chris Tietgen December 5, 2014

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.

Norman Abramovitz
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 5, 2014

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.

Norman Abramovitz
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 5, 2014

I would also turn off validate JQL as well.

Norman Abramovitz
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 5, 2014

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

Chris Tietgen December 5, 2014

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