1
我正在創建一個腳本,負責生成包含有關一組組及其在Google應用腳本中的聯繫人信息的報告。在聯繫人的Google App腳本中超出了最長執行時間API
如果我選擇幾個組,則一切正常,但如果選擇多個(20個或更多),則腳本將啓動「超出最大執行時間」錯誤。
我該如何減少腳本時間執行?
謝謝!
我的(減少)腳本
var allContactsInfo = []
/II. For each group
for(var i = 0 ; i < numberOfGroups ; i++)
{
var selected = eventInfo.parameter["group"+i]
var contactInfo = []
//III. If it has been selected by the user
if(selected)
{
//IV. Get the contact group and contacts
var contactGroup = ContactsApp.getContactGroupById(eventInfo.parameter["group_"+i+"_id"])
var contacts = contactGroup.getContacts()
//IV. Iterate over each group contact
for (var j=0; j < contacts.length; j++)
{
var contact = contacts[j];
contactInfo.push(contact.getGivenName())
contactInfo.push(contact.getFamilyName())
var groups = contact.getContactGroups()
var groupsAsArray = []
for (var k = 0 ; k < groups.length; k++)
{
groupsAsArray.push(groups[k].getName())
}
contactInfo.push(groupsAsArray.sort().join())
//V. Add the contact into the array
allContactsInfo.push(contactInfo)
}
}
...
...
//VI. Fill the spreadsheet with the array built within the loop
sheet.getRange(1, 1, allContactsInfo.length, headers.length).setValues(allContactsInfo);
UPDATE
一些測試後,我發現瓶頸產生返回用戶組(通過contact.getContactGroups())。
返回名字,姓氏,電子郵件地址和電話的工作原理確定,但如果我包括用戶羣太,然後出現超時異常......
更新2
這是我工作的解決方案,希望它能幫助:)
https://github.com/antacerod/google-app-script-6-minutes-limitation
感謝您使用它:-)高興它幫助。這不是一個好主意,可以顯示你的解決方案的實施情況?希望你會花一些時間來這樣做! –
@ serge-insas我已經添加了一個鏈接到我們新的公司github倉庫,我們將盡快寫一篇文章。 –
我看到你的github,確實非常好的工作;)我喜歡使用'case'的雙語Ui ...從來沒有想到過自己。 –