有人可以帮我整理一下吗?我担心我不是太技术化,并且已经删除了各种脚本和建议,但仍然超时....
function cleanUp() {
var batchSize = 100 // Process up to 100 threads at once
var delayDays = 10 // Enter # of days before messages are moved to trash
var maxDate = new Date();
maxDate.setDate(maxDate.getDate()-delayDays);
var label = GmailApp.getUserLabelByName("delete me");
var threads = label.getThreads();
for (var i = 0; i < threads.length; i++) {
if (threads[i].getLastMessageDate()<maxDate)
{
threads[i].moveToTrash();
}
}
}
答案 0 :(得分:0)
要回答的第一个问题是“你有多少线程与标签删除我”? 您似乎已尝试通过使用batchSize变量来限制一次处理的线程数,但您尚未使用它。要一次处理100个标签,您可以稍微修改您的循环
/* This will work on 100 threads at a time */
for (var i = 0; (i < threads.length) && (i < batchSize) ; i++) {
if (threads[i].getLastMessageDate()<maxDate)
{
threads[i].moveToTrash();
}
}
}
另一方面,我认为您不能直接从Date
对象中扣除天数。你可能不得不做这样的事情
var ONE_DAY = 24 * 60 * 60 * 1000; //in ms
var delayDays = 10 // Enter # of days before messages are moved to trash
var maxDate = new Date();
var numDays = delayDays * ONE_DAY ;
maxDate.setTime(maxDate.getTime() - numDays);