Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner: speed-up post fuction custom script

Matthew Van Kuyk
Contributor
March 13, 2018

Dear all,

I know it is a very global question: is there a way to speed-up the execution of scriptrunner scripts.

it is a very simple script.

Elapsed: 2084 ms
CPU time: 1313 ms

Server:

  • 4 Virtual Processors (2,50GHz) - AMD Opteron(tm) Processor 6380
  • 16 GB Ram

JVM:

  • Internal memory pool: 12288
  • Maximum memory pool: 12288

 

Any tips or advice?

 

Kind regards,

 

Matt

1 answer

0 votes
Matt Doar
Community Champion
March 13, 2018

Can you post the guts of the script?

Matt Doar
Community Champion
March 13, 2018

Cos my telepathy bill is huge this month

Matthew Van Kuyk
Contributor
March 13, 2018

Hi Matt,

Sorry to hear that about your bill :-).

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.event.type.EventDispatchOption;

void setSummary(String key,String newSummary) {
    try{
        ComponentManager componentManager = ComponentManager.getInstance();
        IssueManager im = ComponentAccessor.getIssueManager();
        MutableIssue issue = im.getIssueObject(key);
        issue.setSummary(newSummary);

        im.updateIssue(ComponentAccessor.jiraAuthenticationContext.getLoggedInUser(), issue, EventDispatchOption.DO_NOT_DISPATCH, false)
    }catch(Exception ex){
        log.error(ex);
    }
}

def cfCustomerRequestType = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_10001")
def customerRequestTypeValue = (String) issue.getCustomFieldValue(cfCustomerRequestType)

def crt = "";

switch(customerRequestTypeValue){
    case "sd/c0e84f82-b0fa-4455-a35b-459a4482008a":
        def cfFirstName = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_10802") //File share access
        def firstNameValue = (String) issue.getCustomFieldValue(cfFirstName)

        def cfLastName = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_10803") //File share access
        def lastNameValue = (String) issue.getCustomFieldValue(cfLastName)
        
        crt = "("+firstNameValue+" "+lastNameValue+")";
    break;
    case "sd/ffcd2750-6df1-4dad-a6b4-d97375dac5f0":
        def cfName = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_12600") //File share access
        def NameValue = issue.getCustomFieldValue(cfName)
    
        def cfFileShare = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_11501") //File share access
        def fileShareValue = issue.getCustomFieldValue(cfFileShare)
        
        
        crt = "("+NameValue[0].getName() + " - " + fileShareValue[0].getName() +")";
    break;
    case "sd/69293647-7944-470b-b2ee-c02643560a51":
        def cfName = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_12600") //File share access
        def NameValue = issue.getCustomFieldValue(cfName)
    
        def cfApplication = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_11202") //File share access
        def ApplicationValue = issue.getCustomFieldValue(cfApplication)
        
        
        crt = "("+NameValue[0].getName()+ " - " + ApplicationValue[0].getName() +")";
    break;
    case "sd/systemproblem": crt="Report a system problem"; break;
    case "sd/d4e8d12b-f6c7-4c45-a5f2-98d6ffae1efd": crt="Login issue"; break;
    case "sd/d624ae3d-dca1-4d95-b660-053f93f9fe53": crt="Network problem"; break;
    case "sd/334f5c8f-ab42-4c27-aaed-aec34dbd8fa8": crt="Mail issues"; break;
    case "sd/5486c448-1848-467f-bd6a-7bcab790a0d4": crt="Missing or lost hardware"; break;
    case "sd/68b098b2-9634-4bb6-b7cf-ca0a85e2e015": crt="Unlock account"; break;
    case "sd/a97e5bce-feaa-4b77-96f4-43648c9c1528": crt="Reset password"; break;
    case "sd/068b93a6-02f0-47d7-8e1f-883eb78bd220": crt="Report unauthorized access to IT systems"; break;
    case "sd/14156341-2fee-445f-ab8a-f21f3e66c55b": crt="Extend disk space"; break;
    case "sd/d0c0d8f8-6e6a-4774-a386-400aed2ef8ba": crt="Wipe mobile device"; break;
    case "sd/e674cc7a-e556-40fb-9221-d6a21db240b6": crt="Other issue"; break;
    case "sd/69b7b23e-abf8-48e8-8c2c-7777d58edee0": crt="Other request"; break;
    case "sd/e4ae846c-0c8c-4e5a-a423-fe00ee31bd0b": crt="File Share issue"; break;    
    
}
if(customerRequestTypeValue=="sd/c0e84f82-b0fa-4455-a35b-459a4482008a" && customerRequestTypeValue=="sd/ffcd2750-6df1-4dad-a6b4-d97375dac5f0"  && customerRequestTypeValue=="sd/69293647-7944-470b-b2ee-c02643560a51"  ){
    setSummary(issue.getKey(),issue.getSummary()+ " " + crt);
}else{
    setSummary(issue.getKey(),crt + ": " + issue.getSummary());
}

return true;

Matt Doar
Community Champion
March 13, 2018

Nothing obvious jumps out at me, except all the String comparisons in the case statements.

 

I'd start simple and see how that runs. For example, how long does a script take that just calls setSummary with a fixed string. Then add more code. Perhaps use a StringBuilder class instead of concatenating Strings? In the end, some judicious println may show you the time of each part.

Suggest an answer

Log in or Sign up to answer