Feb 20, 2022 01:15 PM
Hi All,
I’m trying to run this automation script that works perfectly on my test base of ~10 records but throws this error when I move it to my real base with ~1100 records.
Error: Script exceeded execution time limit of 30 seconds
The below code is based on this tutorial here, tweaked slightly with recommendations I found in another similar question. Any help or ideas would be appreciated!
Learn Airtable scripting #1: basics & removing duplicates with Giovanni Briggs - YouTube (from Automate All the Things channel)
var table = base.getTable(“Table 1”);
var query = await table.selectRecordsAsync ({
fields: ["Name" ]
});
console.log(query);
let duplicates = query.records.filter((record)=>{
return query.records.find((potentialDuplicate)=>{
return record.getCellValue("Name") === potentialDuplicate.getCellValue("Name") && record.id !== potentialDuplicate.id;
})
});
console.log(duplicates);
let updates = duplicates.map(update => {
return {
"id":update.id,
fields: {
"Duplicate": true
}
}
})
console.log(updates);
while (updates.length>0){
//removed await in front of the below Async to see if that would improve time
table.updateRecordsAsync(updates.slice(0,50));
updates = updates.slice(50);
};
Solved! Go to Solution.
Feb 20, 2022 02:12 PM
Not surprising - think that snippet makes (1100-1)->squared calls to try to find duplicates. e.g., for each row, look at the other 1099 rows - really bad design.
You need to use hash indices to do this fast.
Feb 20, 2022 02:12 PM
Not surprising - think that snippet makes (1100-1)->squared calls to try to find duplicates. e.g., for each row, look at the other 1099 rows - really bad design.
You need to use hash indices to do this fast.
Feb 22, 2022 10:09 AM
Thanks! I will try it out.
Feb 22, 2022 10:17 AM
On a different note…
All asynchronous methods must use await
to function correctly. It’s possible that some updates might not get saved correctly if not await
-ed.