Forums

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

Long load time for jira fragments web panel

Alexander Kreß September 11, 2023

Hey all,

i show a web panel in issue view screen based on insight objects the user add in the create screen. The Insight Objects has outbound references over 4 hierachry levels. When the user type in number in the lowest hierachry level the issue view screen show something like this.

Insight Objects in Web Panel in Issue.PNG

The Code for the Fragments in Jira Script Runner looks like. At the end i store the values in the database that everyone can search.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import customRiadaLibraries.insightmanager.InsightManagerForScriptrunner
import com.atlassian.jira.event.type.EventDispatchOption
import customRiadaLibraries.insightmanager.SimplifiedAttachmentBean
import com.atlassian.jira.issue.ModifiedValue
//import com.riadalabs.jira.plugins.insight.services.model.ObjectBean

def customFieldManager = ComponentAccessor.customFieldManager
InsightManagerForScriptrunner im = new InsightManagerForScriptrunner()

//Issue issue = context.issue as Issue
def issueManager = ComponentAccessor.getIssueManager()

def issueService = ComponentAccessor.getIssueService()
def userManager = ComponentAccessor.getUserManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Issue issue = context.issue as Issue
//Issue issue = issueManager.getIssueObject("CC-6565")

def stringBuilder(Object assets){
  String rowString =  """<td><div class="wrap">
                                <span class="name"><a href="/secure/insight/assets/${assets.getObjectKey()}"</a></span>
                                <div id="${assets.getObjectKey()}-val" class="value type-textfield">
                                  <img src="/rest/insight/1.0/objecttype/${assets.getObjectTypeId()}/icon.png?size=16" width="16px" height="16px">
                                  <a href="https://example/secure/insight/assets/${assets.getObjectKey()}">${assets.getLabel()}</a>
                                </div>
                            </div></td>"""
  return rowString
}

List tempModelValue = []
def rowStringArray = []
def resultRows = ""
def materialstring = ""
def ecostring = ""

      def machineIdsField = customFieldManager.getCustomFieldObject("customfield_14706")
      def machineIdsValue = issue.getCustomFieldValue(machineIdsField)
      def machinesField = customFieldManager.getCustomFieldObject("customfield_14702")
      def machinesValue = issue.getCustomFieldValue(machinesField)
      def modelsIdField = customFieldManager.getCustomFieldObject("customfield_14703")
      def modelsValue = issue.getCustomFieldValue(modelsIdField)
      def pfsField = customFieldManager.getCustomFieldObject("customfield_14704") //Product Familie(s)
      def pfsValue = issue.getCustomFieldValue(pfsField)
      def unitsField = customFieldManager.getCustomFieldObject("customfield_14705")
      def unitsValue = issue.getCustomFieldValue(unitsField)

      def materialfield = customFieldManager.getCustomFieldObject("customfield_14523")
      def materialValue = issue.getCustomFieldValue(materialfield)

      def builtString = new StringBuilder()
      def unitlist = []
      def pfamilylist = []

      if(materialValue){
      materialValue.eachWithIndex{value, i ->
      def materialid = materialValue[i]
      materialstring = materialstring + stringBuilder(materialid)
                                  }
      }                            
      def ecofield = customFieldManager.getCustomFieldObject("customfield_15202")
      def ecoValue = issue.getCustomFieldValue(ecofield)
      if(ecoValue){
      ecoValue.eachWithIndex{value, i ->
      def ecoid = ecoValue[i]
      ecostring = ecostring + """<div class="wrap">
                                <span class="name"><a href="/secure/insight/assets/${ecoid.getObjectKey()}"</a></span>
                                <div id="${ecoid.getObjectKey()}-val" class="value type-textfield">
                                  <img src="/rest/insight/1.0/objecttype/${ecoid.getObjectTypeId()}/icon.png?size=16" width="16px" height="16px">
                                  <a href="https://example/secure/insight/assets/${ecoid.getObjectKey()}">${ecoid.getLabel()}</a>
                                </div>
                            </div>"""
                                  }
      }

      if(machineIdsValue){
        machineIdsValue.eachWithIndex{ value, i ->
        def machineId = machineIdsValue[i]

        machineValue = im.iql(5, """object having inboundReferences(objectType = "Machine ID" AND key = ${machineId.objectKey})""").first()
        modelValue = im.iql(5, """object having inboundReferences(objectType = "Machine" AND key = ${machineValue.objectKey})""").first()
        pfValue = im.iql(5, """object having inboundReferences(objectType = "Model" AND key = ${modelValue.objectKey})""").first()
        unitValue = im.iql(5, """object having inboundReferences(objectType = "Product Family" AND key = ${pfValue.objectKey})""").first()
        pfamilylist.add(pfValue)
        unitlist.add(unitValue)

        builtString.append("<tr>")
        builtString.append(stringBuilder(machineId))
        builtString.append(stringBuilder(machineValue))
        builtString.append(stringBuilder(modelValue))
        builtString.append(stringBuilder(pfValue))
        builtString.append(stringBuilder(unitValue))
        builtString.append("</tr>")
       
      }
      }

      if(machinesValue != null){
        machinesValue.eachWithIndex{ value, i ->
        def machine = machinesValue[i]
        //machineValue = im.iql(5, """object having inboundReferences(objectType = "Machine ID" AND key = ${machineId.objectKey})""")
        modelValue = im.iql(5, """object having inboundReferences(objectType = "Machine" AND key = ${machine.objectKey})""").first()
         tempModelValue.add(modelValue)
        pfValue = im.iql(5, """object having inboundReferences(objectType = "Model" AND key = ${modelValue.objectKey})""").first()
        unitValue = im.iql(5, """object having inboundReferences(objectType = "Product Family" AND key = ${pfValue.objectKey})""").first()
        pfamilylist.add(pfValue)
        unitlist.add(unitValue)

        builtString.append("<tr>")
        builtString.append(stringBuilder(machine))
        builtString.append(stringBuilder(modelValue))
        builtString.append(stringBuilder(pfValue))
        builtString.append(stringBuilder(unitValue))
        builtString.append("</tr>")
      }
      }
 if(machinesValue == null){    
      if(modelsValue != null){
        modelsValue.eachWithIndex{ value, i ->
          if(tempModelValue.contains(modelsValue[i])){
            return
          }
          else{
        def model = modelsValue[i]

        pfValue = im.iql(5, """object having inboundReferences(objectType = "Model" AND key = ${model.objectKey})""").first()
        unitValue = im.iql(5, """object having inboundReferences(objectType = "Product Family" AND key = ${pfValue.objectKey})""").first()
        pfamilylist.add(pfValue)
        unitlist.add(unitValue)

        builtString.append("<tr>")
        builtString.append(stringBuilder(model))
        builtString.append(stringBuilder(pfValue))
        builtString.append(stringBuilder(unitValue))
        builtString.append("</tr>")
        }
      }
      }
 }

String rowString = builtString.toString()
rowStringArray.add(rowString)    
     
for(int j = 0; j < rowStringArray.size(); j++ ){
    resultRows = resultRows + rowStringArray[j]
}

if (pfsValue == null && machineIdsValue == null && modelsValue == null){
  def dummy = ""
}
else {
  def valid = false

  if (pfsValue == null && (machineIdsValue != null || modelsValue != null)){
  issue.setCustomFieldValue(unitsField, unitlist)
  issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
  issue.setCustomFieldValue(pfsField, pfamilylist)
  issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
  }
  else {
    valid = true
  }

  if (valid){
  pfsValue = pfsValue.unique()
  pfamilylist = pfamilylist.unique()
  if (pfsValue.sort() != pfamilylist.sort()){
  issue.setCustomFieldValue(unitsField, unitlist)
  issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
  issue.setCustomFieldValue(pfsField, pfamilylist)
  issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
  }
  }
}

if(resultRows || ecostring || materialstring){
def resultString = """
<table style="width: 100%; text-align: left;">
          <tr>
            <th>PDM Materialnumber</th>
            <th>PDM ECO</th>
          </tr>
          <tr>
            <td>"""+materialstring+"""</td>
            <td>"""+ecostring+"""</td>
          </tr>
          <tr>
            <th>Machine ID</th>
            <th>Machine</th>
            <th>Model</th>
            <th>Product Family</th>
            <th>Unit</th>
          </tr>"""+resultRows+"""
          </table>"""
         
writer.write(resultString)
}
Now when a user wants to open the web panel it takes many seconds to load. I also tried to do that with listeners but the UI isnt as good as with an fragment. Does anybody have some improvements ?

0 answers

Suggest an answer

Log in or Sign up to answer