--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/2453d59b-10ce-4d48-be39-f7fa175c1d83n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAFX%2Bz3UOdStcvzeRTyP6nDvj9W3CDUZW3%3D8FQha0v1jwVPHThA%40mail.gmail.com.
Your script does multiple actions and is dependent on how many files you have in that folder.
It is grabbing all the files and running through every single one and trying to open them as a spreadsheet.
Are all files in that folder a spreadsheet?? You may want to add a check before you try to open a file as a spreadsheet to ensure it is of that type.
Before line 4 below, add a check whether the file is a spreadsheet first..
1. while(files.hasNext())
2. {
3. Logger.log(Duration(startTime) + " Opening Spreadsheet")
4. spreadsheets.push(SpreadsheetApp.openById(files.next().getId()))
5. Logger.log(Duration(startTime) + " Spreadsheet Opened")
6. }
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/570148f6-ad66-47a2-8f6d-e201dd7018c9n%40googlegroups.com.
Hi Josh,
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAFX%2Bz3UOdStcvzeRTyP6nDvj9W3CDUZW3%3D8FQha0v1jwVPHThA%40mail.gmail.com.

Split the getId from the open to see what is actually taking the extra time. But large files will certainly slow down operations. Is there a way for you to reduce its size?
From: google-apps-sc...@googlegroups.com <google-apps-sc...@googlegroups.com> On Behalf Of Josh Dalton
Sent: July 7, 2022 12:39 PM
To: Google Apps Script Community <google-apps-sc...@googlegroups.com>
Subject: Re: [Apps-Script] Re: How would I optimise SpreadsheetApp.OpenByID?
All files in the folder are a spreadsheet and a check isn't necessary, the only thing that is causing this issue is the opening of the first large spreadsheet. Here's a screenshot of all that is in the folder I'm checking
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/905d06f1-fe36-4b01-b6e7-e547ced4cff1n%40googlegroups.com.

Ok. So the get file ID is not the culprit, but opening definitely is. 6 minutes to open a file is most indicative of a corrupted file most likely. I would suggest you copy what content you need from it, delete it and create a new one. Regardless of the size of the file, it should not take that long to open. There is something wrong with the data for that file causing the problem.
From: google-apps-sc...@googlegroups.com <google-apps-sc...@googlegroups.com> On Behalf Of Josh Dalton
Sent: July 7, 2022 1:11 PM
To: Google Apps Script Community <google-apps-sc...@googlegroups.com>
Subject: Re: [Apps-Script] Re: How would I optimise SpreadsheetApp.OpenByID?
There's no way for me to reduce the size of the spreadsheet unfortunately, here are the latest results along with the code change
while(files.hasNext())
{
var file = files.next()
Logger.log(Duration(startTime) + " Fetching File ID")
var fileID = file.getId()
Logger.log(Duration(startTime) + " File ID Fetched")
Logger.log(Duration(startTime) + " Opening " + file.getName())
spreadsheets.push(SpreadsheetApp.openById(fileID))
Logger.log(Duration(startTime) + " " + file.getName() + " Opened")
}

To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/6584d0b2-1b83-4189-88b9-cda52dd5ce59n%40googlegroups.com.