Hi, in our instance we have 2k+ users and 3m+ issuses
I need to get statistic of every text customField on every issue (just table of unique text customField values and it's count)
using groovy script executs 20+minutes
sql just 3 seconds
groovy example
```
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.web.bean.PagerFilter
import groovy.json.JsonOutput
import org.apache.log4j.Logger
def logger = Logger.getLogger("com.acme.CreateSubtask")
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def queryStr = """ "Template Name" is not EMPTY """
def query = jqlQueryParser.parseQuery(queryStr)
def search = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
def statistic = [:]
search.results.each { documentIssue ->
def issue = issueManager.getIssueObject(documentIssue.id)
def customFields = customFieldManager.getCustomFieldObjectsByName("Template Name")
def customField = customFields.first()
def fieldValue = issue.getCustomFieldValue(customField)
if (fieldValue) {
statistic[fieldValue] = (statistic[fieldValue] as Integer)?.plus(1) ?: 1
}
}
return JsonOutput.toJson(statistic)
```
sql example
```
SELECT
cfv.stringvalue AS "Template Name",
COUNT(*) AS Count
FROM
jiraissue AS ji
INNER JOIN
customfieldvalue AS cfv
ON
ji.id = cfv.issue
INNER JOIN
project AS p
ON
ji.project = p.id
WHERE
cfv.customfield = (SELECT id FROM customfield WHERE cfname = 'Template Name') AND
cfv.stringvalue IS NOT NULL
GROUP BY
cfv.stringvalue
ORDER BY
Count DESC;
```
I need to execute sql in jira cloud somehow cause 20 minutes is actually bad comparing to sql, what optimization technics could I use or just how to execute sql?
Hi @Viktor Fedun with the cloud, you won't have SQL access. It was suggested in this article that you could use the API to get access: Pulling Data from system
If there are performance issues, I would suggest opening a ticket with support.
Hope that helps.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.