有没有一种方法可以加快/批处理Google日历的读写速度?

问题描述 投票:0回答:1

我不熟悉Google Apps脚本,并且在进行此项目时正在学习JavaScript。在介绍性代码实验室的过程中,我注意到best practice使用一个命令将所有数据读入数组,执行操作,然后使用一个命令将其写入。

我了解如何在Google表格中使用此功能,但如何在Google日历中使用该功能?我遇到了一些讨论batching with Google Calendar APIAdvanced Google Services的链接,但我不明白如何利用这些信息。 我基本上希望批量编辑事件,而不是在for循环中重复访问Google日历。

function deleteMonth() {

  //  Set Date range to delete 
  var today = new Date();
  var firstDay = new Date(today.getFullYear(), today.getMonth(), 1);
  var lastDay = new Date(today.getFullYear(), today.getMonth() + 1, 0);

  //  read spreadsheet data and get User Info from ss
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var idSheet = spreadsheet.getSheetByName('User Info');
  //Get users from sheet in array of objects with properties from column header in 
  //'User Info' (name, email, year, calName, calID, early, late)
  var userInfo = getSheetData(idSheet);
  var deletedNames = "";
  for (i = 0; i < userInfo.length; i++) {
    var calID = userInfo[i].calID;
    //    if we have calID proceed to delete events
    if (calID) {
      console.time("get events");
      var calendar = CalendarApp.getCalendarById(calID);
      var events = calendar.getEvents(firstDay, lastDay);
      console.timeEnd("get events");
      //    Delete events and add deleted name to string 
      //    deletedNames     
      for (i = 0; i < events.length; i++) {
        console.time("delete event");
        deletedNames += events[i].getTitle() + ", ";
        events[i].deleteEvent();
        console.timeEnd("delete event");
      }
    }
  }
  spreadsheet.toast("Deleted events: \n" + deletedNames);
}

Time output from console.time()

听起来相关的其他相关链接:

  1. Using advanced google services(应用程序脚本资源)
  2. Google Developer blog?

我不熟悉Google Apps脚本,并且在进行此项目时正在学习JavaScript。在介绍性代码实验室的过程中,我注意到了将所有数据读入一个数组的最佳实践,其中一个数组...

javascript performance google-apps-script google-calendar-api
1个回答
0
投票

我相信您的目标如下

© www.soinside.com 2019 - 2024. All rights reserved.