Running ContactsApp.getContact(email) inside a loop causes timeout

89 views
Skip to first unread message

Benjamin

unread,
Jan 5, 2020, 12:09:18 AM1/5/20
to Google Apps Script Community

I'm building a GAS on GmailApp to extract participants from a thread. Then I want to find out their contact info on ContactsApp.

I've tried the following:

1. loop over an array of thread participants emails and do a ContactsApp.getContact(email), however this leads to a timeout.
2. load all contacts into an array with ContactsApp.getContacts() then loop over the array of participants and for each loop over contacts and getEmails() and getAddress(). However this takes several seconds and makes the add-on load in about 6 seconds or so.

I'm assuming I'm not using the stuff as expected. What would be the right way to do that?

Clark Lind

unread,
Jan 5, 2020, 1:50:11 PM1/5/20
to Google Apps Script Community
As long as you give the user some feedback, like a "Loading Contacts...  This may take a few seconds...", 6 seconds isn't terribly too long (in my opinion anyway)

Benjamin

unread,
Jan 5, 2020, 9:44:45 PM1/5/20
to Google Apps Script Community
Hi,

It's 6 seconds with 4 contacts inside the thread and about 1200 contacts in total. What if the thread has 20 contacts for a user with 20,000 contacts? Still I think a timeout is weird.

Currently I'm doing this with the loadAddOn() function and that's perhaps where it is getting cumbersome.

Can I load the UI cards with thread contacts first, and then look for them in the contacts in the background and have a spinner on the card header until the contact is found? Or perhaps when the collapsed card is expanded?

How would I go about doing this?

Benjamin

unread,
Feb 17, 2020, 2:48:55 AM2/17/20
to Google Apps Script Community
Hi, is there any help for this? I was hoping to get some support from the community.

Alex

unread,
Feb 17, 2020, 3:09:21 AM2/17/20
to Google Apps Script Community
If I understand you correctly

I think there is a method for async loading a part of contacts search of Gmail Add-on.

As an extreme case, you can always use an additional widget to select contacts.

Best, Alex.
Reply all
Reply to author
Forward
0 new messages