How to reduce load time ?

prasanna7869
Mega Expert

Hi Team,

I have a concept to Reassign Problem ticket to other group. for this I have a UI Page, which has the Assignment group field (reference) - this lookup should populate only the CMDB_CI supported by groups and the groups from sys_user_group table whose u_lookup_inclusion value is "Y" and reassignment reason (textarea) - this is around 529 groups.

To attain this, I have used two dummy tables. One to collect the required data from both the tables, and in other dummy table I have removed the duplicate entries. I populate the second dummy table's values in the Assignment Group's lookup.

I am getting the correct data that I exactly want . But when I click on the lookup, it is taking nearly 10 seconds to show the records.

this is my Script include :

getSupportedByGroupss : function () {

  try {

var glide = new GlideRecord('u_problem_dummy');

  glide.query();

  while(glide.next()){

  glide.deleteRecord();

  }

var groups=[];

  var gr = new GlideAggregate('cmdb_ci');

  gr.addQuery('u_active','true');

  gr.addNotNullQuery('supported_by');

  gr.groupBy('supported_by');

  gr.query();

  var gg = new GlideRecord('sys_user_group');

  gg.addQuery('u_lookup_inclusion','Y');

  gg.addNotNullQuery('name');

  gg.addQuery('active','true');

  gg.query();

while(gr.next())

  {

  gs.log("1st while");

  if(gr.supported_by!='' || gr.supported_by!='unknown') {

  var glide2 = new GlideRecord('u_problem_dummy');

  glide2.u_groups = gr.supported_by;

  glide2.u_name = glide2.u_groups;

  glide2.insert();

  }

}

  var second = [];

while(gg.next()){

if(gg.name!='' || gg.name!='unknown'){

  var glide1 =   new GlideRecord('u_problem_dummy');

  glide1.u_groups = gg.sys_id;

  glide1.u_lookup_inclusion = gg.u_lookup_inclusion;

  glide1.u_name = glide1.u_groups;

  glide1.insert();

  }

}

  var arrayUtil = new ArrayUtil();

  var dummy1 = new GlideRecord('u_problem_dummy');

  dummy1.addNotNullQuery('u_groups');

  dummy1.query();

  while(dummy1.next()){

  second.push(dummy1.getValue('u_groups'));

  }

var glid = new GlideRecord('u_assignment_group');

  glid.query();

  while(glid.next()){

  glid.deleteRecord();

  }

var arr = [];

  var len = second.length;

for (var i = 0; i < len; i++) {

  for (var j = i + 1; j < len; j++) {

  if (second[i] === second[j])

  j = ++i;

  }

  arr.push(second[i]);

}

  for(var count = 0; count < arr.length; count++){

  var success = new GlideRecord('u_assignment_group');

  success.u_groups = arr[count];

  success.insert();

  }

}

  catch(e) {

  gs.log('8889 Exception : '+e);

  }

  },

Is there any way to reduce the load time of data ? Any help Appreciated

1 ACCEPTED SOLUTION

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Hi Prasanna,



If have several parts in the code where slowness can occur:



1. This part of code:



  try {


var glide = new GlideRecord('u_problem_dummy');


  glide.query();


  while(glide.next()){


  glide.deleteRecord();


  }



Why querying the entire table and then delete records one by one and just not use deleteMultiple method, like:



  try {


var glide = new GlideRecord('u_problem_dummy');


  glide.deleteMultiple()


}



Depending on how big the table is, this can take time.



Same here:



var glid = new GlideRecord('u_assignment_group');


  glid.query();


  while(glid.next()){


  glid.deleteRecord();


  }



Also, you have several GlideRecord calls in the script. Why not test them one by one in background scripts with a gs.print to see how long they take to execute?



Regards,


Sergiu


View solution in original post

3 REPLIES 3

dmfranko
Kilo Guru

Have you looked into using a database view?   I didn't go through your code line by line, so maybe it's not possible, but it might be worth looking in to.


sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Hi Prasanna,



If have several parts in the code where slowness can occur:



1. This part of code:



  try {


var glide = new GlideRecord('u_problem_dummy');


  glide.query();


  while(glide.next()){


  glide.deleteRecord();


  }



Why querying the entire table and then delete records one by one and just not use deleteMultiple method, like:



  try {


var glide = new GlideRecord('u_problem_dummy');


  glide.deleteMultiple()


}



Depending on how big the table is, this can take time.



Same here:



var glid = new GlideRecord('u_assignment_group');


  glid.query();


  while(glid.next()){


  glid.deleteRecord();


  }



Also, you have several GlideRecord calls in the script. Why not test them one by one in background scripts with a gs.print to see how long they take to execute?



Regards,


Sergiu


Thank you Sergiu...