我将 Google Apps 脚本作为 WebApp 发布,但有时使用该脚本的用户会遇到:
Service invoked too many times in a short time: gmail rateMax. Try Utilities.sleep(1000) between calls. (line XXX)
异常告诉我用 a 减慢它Utitlities.sleep(1000)
,但是在这样做之前我想知道最大速率到底是多少。我能找到的唯一文档是配额页面,但上面写着:
GMail Read: 10000 / day
我的脚本距离 10000 次读取还很远。有人知道rateMax
具体指的是什么吗?
更新:导致此问题的代码如下(通过 XHR 调用):
add = function(form) {
// [...]
messageId = (_ref = form.msgId) != null ? _ref : form.messageId;
if (!messageId || !(message = GmailApp.getMessageById(messageId))) {
throw ErrorCodes.INVALID_MESSAGE_ID;
}
// [...]
thread = GmailApp.getThreadById(message.getThread().getId());
if (String(form.archive) === "true") {
thread.moveToArchive();
}
// [...]
addLabel(LABEL_BASE, thread);
addLabel(LABEL_OUTBOX, thread);
};
getLabel = function(name, create) {
var _ref;
return (_ref = GmailApp.getUserLabelByName(name)) != null ? _ref : (create ? GmailApp.createLabel(name) : void 0);
};
addLabel = function(name, thread) {
var _ref;
if ((_ref = this.getLabel(name, true)) != null) {
_ref.addToThread(thread);
}
};
// [...]
表示从示例中删除的不调用 GMail API 的代码。