是否可以并行处理多个电子表格?
Is it possible to process multiple spreadsheets in parallel?
我们在 Google 电子表格中有一个电子表格,其中每一行包含一个 link 到另一个电子表格,如下所示:
我继承了一个解析第一个电子表格的“Google Apps 脚本”脚本,然后使用 SpreadSheetApp class 的 openById 方法依次打开每个指向的电子表格(有数百个),收集从每个电子表格中提取一些值并将它们放入另一个电子表格中。
这显然非常慢,以至于脚本必须管理 continuationToken 并将其重新注入自身才能完成整个过程。
我正在尝试优化整个事情。
我读过 :
- https://developers.google.com/apps-script/guides/support/best-practices
- https://ramblings.mcpher.com/orchestration-of-apps-scripts-parallel-threads-and-defeating-quotas/ , https://github.com/brucemcpherson/gasThreader
还研究了触发器,
urlFetchAll
,等等。
我不知道如何避免逐一打开每个电子表格,从而“尽量减少对其他服务的调用”(@best practices)。
就处理时间而言,可能有更有效的方法。
我在 Gas api 中找不到类似 C# 的 Parallel.ForEach 的东西。
任何指针?
我应该完全重写整个逻辑吗?
来自问题
I don't see how i can avoid opening each spreadsheet one by one, and thus "minimize calls to other services" (@best practices).
我认为在 Google Apps 脚本中没有办法做到这一点。您可以按照 Bruce Mcpherson(问题中包含的链接之一的作者)的建议,尝试使用客户端代码并行打开一些电子表格。据我所知,由于 Google Apps 脚本配额,单个帐户无法同时打开数百个电子表格。
I couldn't find in the Gas api something like C#'s Parallel.ForEach. Any pointers ?
根据您需要执行的操作,使用 Advanced Spreadsheet Service and batchUpdate
(see this example)
可能会有所帮助
Should I completely rework the whole logic ?
这个问题没有足够的细节,但考虑到您继承了脚本并决定使用高级电子表格服务,您很可能应该结束对整个逻辑的返工甚至更改“系统”(也许你不应该为此使用 Google Apps Script / Google Sheets。
我们在 Google 电子表格中有一个电子表格,其中每一行包含一个 link 到另一个电子表格,如下所示:
我继承了一个解析第一个电子表格的“Google Apps 脚本”脚本,然后使用 SpreadSheetApp class 的 openById 方法依次打开每个指向的电子表格(有数百个),收集从每个电子表格中提取一些值并将它们放入另一个电子表格中。
这显然非常慢,以至于脚本必须管理 continuationToken 并将其重新注入自身才能完成整个过程。
我正在尝试优化整个事情。
我读过 :
- https://developers.google.com/apps-script/guides/support/best-practices
- https://ramblings.mcpher.com/orchestration-of-apps-scripts-parallel-threads-and-defeating-quotas/ , https://github.com/brucemcpherson/gasThreader
还研究了触发器,
urlFetchAll
,等等。
我不知道如何避免逐一打开每个电子表格,从而“尽量减少对其他服务的调用”(@best practices)。
就处理时间而言,可能有更有效的方法。
我在 Gas api 中找不到类似 C# 的 Parallel.ForEach 的东西。 任何指针? 我应该完全重写整个逻辑吗?
来自问题
I don't see how i can avoid opening each spreadsheet one by one, and thus "minimize calls to other services" (@best practices).
我认为在 Google Apps 脚本中没有办法做到这一点。您可以按照 Bruce Mcpherson(问题中包含的链接之一的作者)的建议,尝试使用客户端代码并行打开一些电子表格。据我所知,由于 Google Apps 脚本配额,单个帐户无法同时打开数百个电子表格。
I couldn't find in the Gas api something like C#'s Parallel.ForEach. Any pointers ?
根据您需要执行的操作,使用 Advanced Spreadsheet Service and batchUpdate
(see this example)
Should I completely rework the whole logic ?
这个问题没有足够的细节,但考虑到您继承了脚本并决定使用高级电子表格服务,您很可能应该结束对整个逻辑的返工甚至更改“系统”(也许你不应该为此使用 Google Apps Script / Google Sheets。