Fix gmail-label-cleanup: reduce batch size to 100 (API limit)
This commit is contained in:
@@ -39,14 +39,14 @@ function mergeLabels() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Logger.log('Merging ' + m.from + ' -> ' + m.to);
|
Logger.log('Merging ' + m.from + ' -> ' + m.to);
|
||||||
var threads = fromLabel.getThreads(0, 500);
|
var threads = fromLabel.getThreads(0, 100);
|
||||||
var total = 0;
|
var total = 0;
|
||||||
while (threads.length > 0) {
|
while (threads.length > 0) {
|
||||||
toLabel.addToThreads(threads);
|
toLabel.addToThreads(threads);
|
||||||
fromLabel.removeFromThreads(threads);
|
fromLabel.removeFromThreads(threads);
|
||||||
total += threads.length;
|
total += threads.length;
|
||||||
Utilities.sleep(1000);
|
Utilities.sleep(1000);
|
||||||
threads = fromLabel.getThreads(0, 500);
|
threads = fromLabel.getThreads(0, 100);
|
||||||
}
|
}
|
||||||
Logger.log('Moved ' + total + ' threads: ' + m.from + ' -> ' + m.to);
|
Logger.log('Moved ' + total + ' threads: ' + m.from + ' -> ' + m.to);
|
||||||
fromLabel.deleteLabel();
|
fromLabel.deleteLabel();
|
||||||
@@ -69,7 +69,7 @@ function archiveCvlp() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Logger.log('Processing cvlp: relabeling to Newsletter and archiving...');
|
Logger.log('Processing cvlp: relabeling to Newsletter and archiving...');
|
||||||
var threads = cvlpLabel.getThreads(0, 500);
|
var threads = cvlpLabel.getThreads(0, 100);
|
||||||
var total = 0;
|
var total = 0;
|
||||||
while (threads.length > 0) {
|
while (threads.length > 0) {
|
||||||
newsletterLabel.addToThreads(threads);
|
newsletterLabel.addToThreads(threads);
|
||||||
@@ -77,7 +77,7 @@ function archiveCvlp() {
|
|||||||
threads.forEach(function(t) { t.moveToArchive(); });
|
threads.forEach(function(t) { t.moveToArchive(); });
|
||||||
total += threads.length;
|
total += threads.length;
|
||||||
Utilities.sleep(1000);
|
Utilities.sleep(1000);
|
||||||
threads = cvlpLabel.getThreads(0, 500);
|
threads = cvlpLabel.getThreads(0, 100);
|
||||||
}
|
}
|
||||||
Logger.log('Archived ' + total + ' cvlp threads');
|
Logger.log('Archived ' + total + ' cvlp threads');
|
||||||
cvlpLabel.deleteLabel();
|
cvlpLabel.deleteLabel();
|
||||||
@@ -99,14 +99,14 @@ function mergePurchasesIntoReceipt() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Logger.log('Merging purchases -> Receipt...');
|
Logger.log('Merging purchases -> Receipt...');
|
||||||
var threads = purchasesLabel.getThreads(0, 500);
|
var threads = purchasesLabel.getThreads(0, 100);
|
||||||
var total = 0;
|
var total = 0;
|
||||||
while (threads.length > 0) {
|
while (threads.length > 0) {
|
||||||
receiptLabel.addToThreads(threads);
|
receiptLabel.addToThreads(threads);
|
||||||
purchasesLabel.removeFromThreads(threads);
|
purchasesLabel.removeFromThreads(threads);
|
||||||
total += threads.length;
|
total += threads.length;
|
||||||
Utilities.sleep(1000);
|
Utilities.sleep(1000);
|
||||||
threads = purchasesLabel.getThreads(0, 500);
|
threads = purchasesLabel.getThreads(0, 100);
|
||||||
}
|
}
|
||||||
Logger.log('Moved ' + total + ' threads: purchases -> Receipt');
|
Logger.log('Moved ' + total + ' threads: purchases -> Receipt');
|
||||||
purchasesLabel.deleteLabel();
|
purchasesLabel.deleteLabel();
|
||||||
@@ -124,14 +124,14 @@ function restructureBusinessLabels() {
|
|||||||
donationsLabel = GmailApp.createLabel('donations');
|
donationsLabel = GmailApp.createLabel('donations');
|
||||||
}
|
}
|
||||||
Logger.log('Moving business/donations -> donations (top-level)');
|
Logger.log('Moving business/donations -> donations (top-level)');
|
||||||
var threads = bizDonations.getThreads(0, 500);
|
var threads = bizDonations.getThreads(0, 100);
|
||||||
var total = 0;
|
var total = 0;
|
||||||
while (threads.length > 0) {
|
while (threads.length > 0) {
|
||||||
donationsLabel.addToThreads(threads);
|
donationsLabel.addToThreads(threads);
|
||||||
bizDonations.removeFromThreads(threads);
|
bizDonations.removeFromThreads(threads);
|
||||||
total += threads.length;
|
total += threads.length;
|
||||||
Utilities.sleep(1000);
|
Utilities.sleep(1000);
|
||||||
threads = bizDonations.getThreads(0, 500);
|
threads = bizDonations.getThreads(0, 100);
|
||||||
}
|
}
|
||||||
Logger.log('Moved ' + total + ' threads to top-level donations');
|
Logger.log('Moved ' + total + ' threads to top-level donations');
|
||||||
bizDonations.deleteLabel();
|
bizDonations.deleteLabel();
|
||||||
@@ -147,14 +147,14 @@ function restructureBusinessLabels() {
|
|||||||
bizSelling = GmailApp.createLabel('business/selling');
|
bizSelling = GmailApp.createLabel('business/selling');
|
||||||
}
|
}
|
||||||
Logger.log('Moving selling -> business/selling');
|
Logger.log('Moving selling -> business/selling');
|
||||||
var threads = sellingLabel.getThreads(0, 500);
|
var threads = sellingLabel.getThreads(0, 100);
|
||||||
var total = 0;
|
var total = 0;
|
||||||
while (threads.length > 0) {
|
while (threads.length > 0) {
|
||||||
bizSelling.addToThreads(threads);
|
bizSelling.addToThreads(threads);
|
||||||
sellingLabel.removeFromThreads(threads);
|
sellingLabel.removeFromThreads(threads);
|
||||||
total += threads.length;
|
total += threads.length;
|
||||||
Utilities.sleep(1000);
|
Utilities.sleep(1000);
|
||||||
threads = sellingLabel.getThreads(0, 500);
|
threads = sellingLabel.getThreads(0, 100);
|
||||||
}
|
}
|
||||||
Logger.log('Moved ' + total + ' threads to business/selling');
|
Logger.log('Moved ' + total + ' threads to business/selling');
|
||||||
sellingLabel.deleteLabel();
|
sellingLabel.deleteLabel();
|
||||||
@@ -167,13 +167,13 @@ function restructureBusinessLabels() {
|
|||||||
}
|
}
|
||||||
if (contractLabel) {
|
if (contractLabel) {
|
||||||
Logger.log('Removing contract label from all threads...');
|
Logger.log('Removing contract label from all threads...');
|
||||||
var threads = contractLabel.getThreads(0, 500);
|
var threads = contractLabel.getThreads(0, 100);
|
||||||
var total = 0;
|
var total = 0;
|
||||||
while (threads.length > 0) {
|
while (threads.length > 0) {
|
||||||
contractLabel.removeFromThreads(threads);
|
contractLabel.removeFromThreads(threads);
|
||||||
total += threads.length;
|
total += threads.length;
|
||||||
Utilities.sleep(1000);
|
Utilities.sleep(1000);
|
||||||
threads = contractLabel.getThreads(0, 500);
|
threads = contractLabel.getThreads(0, 100);
|
||||||
}
|
}
|
||||||
contractLabel.deleteLabel();
|
contractLabel.deleteLabel();
|
||||||
Logger.log('Deleted contract label (' + total + ' threads unaffected)');
|
Logger.log('Deleted contract label (' + total + ' threads unaffected)');
|
||||||
@@ -201,13 +201,13 @@ function deleteUnusedLabels() {
|
|||||||
Logger.log('Not found (already gone?): ' + name);
|
Logger.log('Not found (already gone?): ' + name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var threads = label.getThreads(0, 500);
|
var threads = label.getThreads(0, 100);
|
||||||
var total = 0;
|
var total = 0;
|
||||||
while (threads.length > 0) {
|
while (threads.length > 0) {
|
||||||
label.removeFromThreads(threads);
|
label.removeFromThreads(threads);
|
||||||
total += threads.length;
|
total += threads.length;
|
||||||
Utilities.sleep(500);
|
Utilities.sleep(500);
|
||||||
threads = label.getThreads(0, 500);
|
threads = label.getThreads(0, 100);
|
||||||
}
|
}
|
||||||
if (total > 0) {
|
if (total > 0) {
|
||||||
Logger.log('Removed label from ' + total + ' threads: ' + name);
|
Logger.log('Removed label from ' + total + ' threads: ' + name);
|
||||||
|
|||||||
Reference in New Issue
Block a user