表格脚本的执行突然变得很慢,并且所有函数的持续时间都增加了

时间:2019-05-15 22:49:56

标签: google-apps-script google-sheets execution-time

我有一个Google Sheets脚本(实际上是几个),它们始终表现良好。在短短几秒钟内就可以执行。现在每个人都需要几分钟!

我通过选项卡之一中的图片按钮运行这些脚本,每个月大约运行2次,因为它们与付款/计费有关。

我上次运行它(大约2周前)时,我发现它运行非常缓慢,因此我决定离开计算机,然后再回来。当我返回脚本时,脚本已经完成。

我认为这是fl幸,因为脚本没有更改,所以我认为这是互联网的问题。因此,我再次尝试了该脚本,并且运行了仅几秒钟。

现在,两周后,我去运行脚本,每个脚本花费的时间要长一个数量级,甚至更多。

我查看了执行记录,没有发现错误,只有很长一段时间。请记住,我能到达的每张纸只有39行!

我已检查Chrome浏览器版本为最新版本。

我已经刷新并重新启动。

代码:

function grabTotals() {
  var ss = SpreadsheetApp.getActiveSpreadsheet(),
      temp = ss.getSheetByName('TEMPLATE'),
      j = 0, // set for rows to populate amounts
      sumTotal = 0, //adding up for TOTAL on report
      all = ss.getSheetByName('BILLING_DASHBOARD'),
      sheets = ss.getSheets(),
      vals = all.getRange('d6:j').getValues();  // (WAS d5) Must set row before what is needed or it misses last counted down item
  ss.getSheetByName("SummaryTotals").activate().getRange("B2:C100").clearContent();

  for (var i = vals.length-1; i > 0; i--) {
    var name = vals[i][6]; //make array of the names from column
    if (name !='') {
      //Set up here an IF for checking vals[i][1] or [0] for the TRUE checkmark
      var isOn = vals[i][0]; // check for checkbox
      if (isOn) {
        var theActiveSheet = ss.getSheetByName(name);
        if (theActiveSheet !=null) {

          Logger.log(theActiveSheet &"---"& theActiveSheet.getName());

          var theAmounts = theActiveSheet.getRange("I13").getValues(); //Get the Total for check on named sheet

          if( theAmounts > 0) {//Zeros are not shown on summary or totaled
              ss.getSheetByName("SummaryTotals").getRange(3+j, 3).setValue(theAmounts); //Write amount from named sheet to the Summary sheet
              ss.getSheetByName("SummaryTotals").getRange(3+j, 2).setValue(vals[i][1]); //Write the NAME on the sheet to the Summary sheet

              Logger.log(theActiveSheet &"|||"& theActiveSheet.getName() &"|||"& theAmounts & "|||"& vals[i][1]);

              ss.getSheetByName("SummaryTotals").insertRows(4+j, 1);  //insert a row (May not be necessary)
              sumTotal = parseFloat(sumTotal) + parseFloat(theAmounts); //Keep a running balance for the Total on the Summary Sheet... done below
              j++;
          }
        }
      }
    }
  }

  multiSortColumns(); // UNCOMMENT for sorting.
  ss.getSheetByName("SummaryTotals").getRange(4+j, 2).setValue("Total");
  ss.getSheetByName("SummaryTotals").getRange(4+j, 3).setValue(sumTotal);
}

执行记录

[19-05-15 15:23:11:903 PDT] Starting execution
[19-05-15 15:23:11:917 PDT] SpreadsheetApp.getActiveSheet() [0 seconds]
[19-05-15 15:23:12:194 PDT] Sheet.protect() [0.276 seconds]
[19-05-15 15:23:22:627 PDT] Protection.setDescription([Sample protected sheet]) [10.432 seconds]
[19-05-15 15:23:22:628 PDT] Session.getEffectiveUser() [0 seconds]
[19-05-15 15:23:22:629 PDT] User.getEmail() [0 seconds]
[19-05-15 15:23:32:743 PDT] Protection.addEditor([jgarner@usmpllc.com]) [10.114 seconds]
[19-05-15 15:23:32:744 PDT] Protection.getEditors() [0 seconds]
[19-05-15 15:23:43:122 PDT] Protection.removeEditors([[jgarner@usmpllc.com]]) [10.378 seconds]
[19-05-15 15:23:43:123 PDT] Protection.canDomainEdit() [0 seconds]
[19-05-15 15:23:43:124 PDT] SpreadsheetApp.getActiveSpreadsheet() [0 seconds]
[19-05-15 15:23:43:125 PDT] Spreadsheet.getSheetByName([TEMPLATE]) [0 seconds]
[19-05-15 15:23:43:125 PDT] Spreadsheet.getSheetByName([BILLING_DASHBOARD]) [0 seconds]
[19-05-15 15:23:43:131 PDT] Spreadsheet.getSheets() [0.006 seconds]
[19-05-15 15:23:43:132 PDT] Sheet.getRange([d6:j]) [0 seconds]
[19-05-15 15:23:53:561 PDT] Range.getValues() [10.428 seconds]
[19-05-15 15:23:53:562 PDT] Spreadsheet.getSheetByName([SummaryTotals]) [0 seconds]
[19-05-15 15:23:53:562 PDT] Sheet.activate() [0 seconds]
[19-05-15 15:23:53:563 PDT] Sheet.getRange([B2:C100]) [0 seconds]
[19-05-15 15:23:53:564 PDT] Range.clearContent() [0 seconds]
[19-05-15 15:23:53:564 PDT] Spreadsheet.getSheetByName([jgaul]) [0 seconds]
[19-05-15 15:23:53:564 PDT] Sheet.getName() [0 seconds]
[19-05-15 15:23:53:565 PDT] Logger.log([0.0, []]) [0 seconds]
[19-05-15 15:23:53:566 PDT] Sheet.getRange([I13]) [0 seconds]
[19-05-15 15:24:14:130 PDT] Range.getValues() [20.564 seconds]
[19-05-15 15:24:14:131 PDT] Spreadsheet.getSheetByName([SummaryTotals]) [0 seconds]
[19-05-15 15:24:14:132 PDT] Sheet.getRange([3, 3]) [0 seconds]
[19-05-15 15:24:14:133 PDT] Range.setValue([[[4200.0]]]) [0 seconds]
[19-05-15 15:24:14:133 PDT] Spreadsheet.getSheetByName([SummaryTotals]) [0 seconds]
[19-05-15 15:24:14:134 PDT] Sheet.getRange([3, 2]) [0 seconds]
[19-05-15 15:24:14:134 PDT] Range.setValue([Jay Gaul]) [0 seconds]
[19-05-15 15:24:14:134 PDT] Sheet.getName() [0 seconds]
[19-05-15 15:24:14:135 PDT] Logger.log([0.0, []]) [0 seconds]
[19-05-15 15:24:14:135 PDT] Spreadsheet.getSheetByName([SummaryTotals]) [0 seconds]
[19-05-15 15:24:24:375 PDT] Sheet.insertRows([4, 1]) [10.239 seconds]
[19-05-15 15:24:24:479 PDT] Spreadsheet.getSheetByName([jgarner]) [0.103 seconds]
[19-05-15 15:24:24:480 PDT] Sheet.getName() [0 seconds]
[19-05-15 15:24:24:480 PDT] Logger.log([0.0, []]) [0 seconds]
[19-05-15 15:24:24:481 PDT] Sheet.getRange([I13]) [0 seconds]
[19-05-15 15:24:34:489 PDT] Range.getValues() [10.007 seconds]
[19-05-15 15:24:34:489 PDT] Spreadsheet.getSheetByName([SummaryTotals]) [0 seconds]
[19-05-15 15:24:34:490 PDT] Sheet.getRange([4, 3]) [0 seconds]
[19-05-15 15:24:34:490 PDT] Range.setValue([[[3850.0]]]) [0 seconds]
[19-05-15 15:24:34:491 PDT] Spreadsheet.getSheetByName([SummaryTotals]) [0 seconds]
[19-05-15 15:24:34:491 PDT] Sheet.getRange([4, 2]) [0 seconds]
[19-05-15 15:24:34:492 PDT] Range.setValue([Jim Garner]) [0 seconds]
[19-05-15 15:24:34:505 PDT] Sheet.getName() [0 seconds]
[19-05-15 15:24:34:506 PDT] Logger.log([0.0, []]) [0 seconds]
[19-05-15 15:24:34:507 PDT] Spreadsheet.getSheetByName([SummaryTotals]) [0 seconds]
[19-05-15 15:24:44:758 PDT] Sheet.insertRows([5, 1]) [10.25 seconds]
[19-05-15 15:24:44:862 PDT] Spreadsheet.getSheetByName([gimes]) [0.103 seconds]
[19-05-15 15:24:44:862 PDT] Sheet.getName() [0 seconds]
[19-05-15 15:24:44:863 PDT] Logger.log([0.0, []]) [0 seconds]
[19-05-15 15:24:44:863 PDT] Sheet.getRange([I13]) [0 seconds]
[19-05-15 15:24:54:868 PDT] Range.getValues() [10.004 seconds]
[19-05-15 15:24:54:869 PDT] Spreadsheet.getSheetByName([SummaryTotals]) [0 seconds]
[19-05-15 15:24:54:869 PDT] Sheet.getRange([5, 3]) [0 seconds]
[19-05-15 15:24:54:870 PDT] Range.setValue([[[3456.6]]]) [0 seconds]
[19-05-15 15:24:54:870 PDT] Spreadsheet.getSheetByName([SummaryTotals]) [0 seconds]
[19-05-15 15:24:54:870 PDT] Sheet.getRange([5, 2]) [0 seconds]
[19-05-15 15:24:54:871 PDT] Range.setValue([Grant Imes]) [0 seconds]
[19-05-15 15:24:54:871 PDT] Sheet.getName() [0 seconds]
[19-05-15 15:24:54:872 PDT] Logger.log([0.0, []]) [0 seconds]
[19-05-15 15:24:54:872 PDT] Spreadsheet.getSheetByName([SummaryTotals]) [0 seconds]
[19-05-15 15:25:05:595 PDT] Sheet.insertRows([6, 1]) [10.722 seconds]
[19-05-15 15:25:05:596 PDT] SpreadsheetApp.getActiveSpreadsheet() [0 seconds]
[19-05-15 15:25:05:696 PDT] Spreadsheet.getSheetByName([SummaryTotals]) [0.099 seconds]
[19-05-15 15:25:05:697 PDT] Sheet.getRange([B3:C]) [0 seconds]
[19-05-15 15:25:05:697 PDT] Range.sort([[{column=2.0, ascending=true}]]) [0 seconds]
[19-05-15 15:25:05:801 PDT] Spreadsheet.toast([Sort complete.]) [0.103 seconds]
[19-05-15 15:25:05:802 PDT] Spreadsheet.getSheetByName([SummaryTotals]) [0 seconds]
[19-05-15 15:25:05:803 PDT] Sheet.getRange([7, 2]) [0 seconds]
[19-05-15 15:25:05:803 PDT] Range.setValue([Total]) [0 seconds]
[19-05-15 15:25:05:804 PDT] Spreadsheet.getSheetByName([SummaryTotals]) [0 seconds]
[19-05-15 15:25:05:804 PDT] Sheet.getRange([7, 3]) [0 seconds]
[19-05-15 15:25:05:805 PDT] Range.setValue([11506.6]) [0 seconds]
[19-05-15 15:25:15:777 PDT] Execution succeeded [82.682 seconds total runtime]

我不是一个好的脚本编写者,但是我确实可以使一切正常运行! 但是,这超出了我的感觉……好像一切都一下子破裂了,让我想知道Google是否发生了我不知道的巨大变化。 **我是否已支付我的GSuite帐单?

请帮助我确定问题所在,并在下一个计费周期之前解决该问题!

没有错误。只是很长的执行,这是以前从未发生过的。

0 个答案:

没有答案