Fix gmail-label-cleanup: reduce batch size to 100 (API limit)

This commit is contained in:
2026-03-06 16:04:15 +00:00
parent 1bb41f5cc9
commit 06646b5dee
+14 -14
View File
@@ -39,14 +39,14 @@ function mergeLabels() {
}
Logger.log('Merging ' + m.from + ' -> ' + m.to);
var threads = fromLabel.getThreads(0, 500);
var threads = fromLabel.getThreads(0, 100);
var total = 0;
while (threads.length > 0) {
toLabel.addToThreads(threads);
fromLabel.removeFromThreads(threads);
total += threads.length;
Utilities.sleep(1000);
threads = fromLabel.getThreads(0, 500);
threads = fromLabel.getThreads(0, 100);
}
Logger.log('Moved ' + total + ' threads: ' + m.from + ' -> ' + m.to);
fromLabel.deleteLabel();
@@ -69,7 +69,7 @@ function archiveCvlp() {
}
Logger.log('Processing cvlp: relabeling to Newsletter and archiving...');
var threads = cvlpLabel.getThreads(0, 500);
var threads = cvlpLabel.getThreads(0, 100);
var total = 0;
while (threads.length > 0) {
newsletterLabel.addToThreads(threads);
@@ -77,7 +77,7 @@ function archiveCvlp() {
threads.forEach(function(t) { t.moveToArchive(); });
total += threads.length;
Utilities.sleep(1000);
threads = cvlpLabel.getThreads(0, 500);
threads = cvlpLabel.getThreads(0, 100);
}
Logger.log('Archived ' + total + ' cvlp threads');
cvlpLabel.deleteLabel();
@@ -99,14 +99,14 @@ function mergePurchasesIntoReceipt() {
}
Logger.log('Merging purchases -> Receipt...');
var threads = purchasesLabel.getThreads(0, 500);
var threads = purchasesLabel.getThreads(0, 100);
var total = 0;
while (threads.length > 0) {
receiptLabel.addToThreads(threads);
purchasesLabel.removeFromThreads(threads);
total += threads.length;
Utilities.sleep(1000);
threads = purchasesLabel.getThreads(0, 500);
threads = purchasesLabel.getThreads(0, 100);
}
Logger.log('Moved ' + total + ' threads: purchases -> Receipt');
purchasesLabel.deleteLabel();
@@ -124,14 +124,14 @@ function restructureBusinessLabels() {
donationsLabel = GmailApp.createLabel('donations');
}
Logger.log('Moving business/donations -> donations (top-level)');
var threads = bizDonations.getThreads(0, 500);
var threads = bizDonations.getThreads(0, 100);
var total = 0;
while (threads.length > 0) {
donationsLabel.addToThreads(threads);
bizDonations.removeFromThreads(threads);
total += threads.length;
Utilities.sleep(1000);
threads = bizDonations.getThreads(0, 500);
threads = bizDonations.getThreads(0, 100);
}
Logger.log('Moved ' + total + ' threads to top-level donations');
bizDonations.deleteLabel();
@@ -147,14 +147,14 @@ function restructureBusinessLabels() {
bizSelling = GmailApp.createLabel('business/selling');
}
Logger.log('Moving selling -> business/selling');
var threads = sellingLabel.getThreads(0, 500);
var threads = sellingLabel.getThreads(0, 100);
var total = 0;
while (threads.length > 0) {
bizSelling.addToThreads(threads);
sellingLabel.removeFromThreads(threads);
total += threads.length;
Utilities.sleep(1000);
threads = sellingLabel.getThreads(0, 500);
threads = sellingLabel.getThreads(0, 100);
}
Logger.log('Moved ' + total + ' threads to business/selling');
sellingLabel.deleteLabel();
@@ -167,13 +167,13 @@ function restructureBusinessLabels() {
}
if (contractLabel) {
Logger.log('Removing contract label from all threads...');
var threads = contractLabel.getThreads(0, 500);
var threads = contractLabel.getThreads(0, 100);
var total = 0;
while (threads.length > 0) {
contractLabel.removeFromThreads(threads);
total += threads.length;
Utilities.sleep(1000);
threads = contractLabel.getThreads(0, 500);
threads = contractLabel.getThreads(0, 100);
}
contractLabel.deleteLabel();
Logger.log('Deleted contract label (' + total + ' threads unaffected)');
@@ -201,13 +201,13 @@ function deleteUnusedLabels() {
Logger.log('Not found (already gone?): ' + name);
return;
}
var threads = label.getThreads(0, 500);
var threads = label.getThreads(0, 100);
var total = 0;
while (threads.length > 0) {
label.removeFromThreads(threads);
total += threads.length;
Utilities.sleep(500);
threads = label.getThreads(0, 500);
threads = label.getThreads(0, 100);
}
if (total > 0) {
Logger.log('Removed label from ' + total + ' threads: ' + name);