javascript - 如何优化此 Google Apps 脚本?它所做的只是读取和写入数据,但它需要永远
问题描述
我有(我认为是)一个简单的 Google Apps 脚本,它从 URL 中获取参数,并根据一行中的两个单元格是否与两个参数匹配,使用它们将数据写入电子表格:
function doGet(e) {
var email = e.parameter.email;
var originalTitle = e.parameter.originalTitle;
var newTitle = e.parameter.newTitle;
var newAdditionalAuthors = e.parameter.newAdditionalAuthors;
var newTechnicalSessions = e.parameter.newTechnicalSessions;
var newApproval = e.parameter.newApproval;
var sh = SpreadsheetApp.openById("18vghxzzt27FcBOvoG8kIFFtswMB7XTsMRg60DJ6_-QM").getSheetByName("Responses");
var data = sh.getDataRange().getValues(); // read all data in the sheet
for (n=0;n<data.length;++n){
if (data[n][2] == email && data[n][3] == originalTitle){ //Find all rows where the email matches the submitter's and the title matches the original
data[n][3] = newTitle;
data[n][31] = newAdditionalAuthors;
data[n][33] = newTechnicalSessions;
data[n][34] = newApproval;
};
sh.getRange(1,1,data.length,data[0].length).setValues(data); // write back to the sheet
}
return ContentService.createTextOutput("Success. You may close this tab.");
}
但是,脚本运行似乎需要相当多的时间,而且工作表中的条目越多,情况就越糟。有人可以告诉我我做错了什么吗?
解决方案
推荐阅读
- javascript - 节点JS中的数组对象相乘和最终总和
- fonts - 如何在 Windows 上修复 Firefox 中的泄漏字体
- vba - 基于 Xpath 的 Selenium (VBA) 点击可以根据单元格上的值进行更改
- caching - 搜索结果是否缓存?
- javascript - 如何将多维关联 PHP 数组中的值作为字符串放入 Javascript 数组中?
- c# - 为什么 ef 一旦 SaveChanges 就失去了关系?
- visual-studio - Visual Studio 开始工作非常缓慢
- linux - 无法使用 crontab 运行 .sh 脚本
- flutter - 如何在颤动中使图像适合屏幕的 1/3
- html - 固定宽度 div 中包含的绝对 div 的可变宽度