Reputation: 35
I'm writing a google app script, that sync our crm-contacts to google contacts.
I've a trigger every 10 minutes and only sync 10 contacts per run. But i get many script-timeouts per day.
I found out, that the slowest operation in my script is
// Contact already exist?
var existing = ContactsApp.getContactsByCustomField(id, 'crmId');
It takes around 20-30 seconds (!!!)
Any Idea why this crucial function is that slow? Or what can I do to find contacts, that already exist in google? Unfortunately, the crmId is the only unique Field to identify the contact.
Upvotes: 0
Views: 333
Reputation: 35
Thank you for the hints.
The ContactGroup.getContacts()
takes the same time as ContactsApp.getContactsByCustomField()
.
So now I store all contacts in an array once and in the loop, I search this array myself as mentioned by Mogsdad. This works fine for me.
Upvotes: 0
Reputation: 19864
That query is slow, Ive used it before too. Back then I noticed that the full http api for contacts doesnt have that query so it seems that apps script is actually searching manually all contacts until if finds that one. I actually ended up using apps script for that proyect because gas had that search possibility but it certainly looks like google doesnt index by custom fields.
Upvotes: 1