I need this script that process a big big table of arround 20k rows, 50 columns.
As of now, the script only manages to process 10k rows before running out of time.
I've tried to optimize as much as possible but I'm afraid i've run into the limit of my habilities:
This is my code nowadays:
function updateValues() {
var ws1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("FINAL").getDataRange();
var ws3List = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("WS2").getDataRange().getValues();
var ws2List = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("WS3").getDataRange().getValues();
var results = new Array;
var data1 = ws1.getValues();
var data1Length = data1.length;
var ws2Length = ws2List.length;
var ws3Length = ws3List.length;
var data1LengthHorizontal = data1[1].length;
for ( var i = 2; i < data1Length; i++ ) {
var iterHotel = data1[i][0];
results[i-2] = [];
for ( var nn=0; nn < ws2Length; ++nn ){
if (iterHotel == ws2List[nn][2]){
var ws2Code = ws2List[nn][4];
break;
}
}
// First Vlookup
var ws3Check;
for ( var nn=0; nn < ws3Length; ++nn ){
if (iterHotel == ws3List[nn][0]){
ws3Check = true;
break;
}
ws3Check = false;
}
// Second Vlookup
var score;
var countries = data1[0];
if (ws3Check) {score = aCalculator1(ws2Code);} else {score = aCalculator2(ws2Code);}
for ( var i1 = 2; i1 < data1LengthHorizontal; i1++){
if (data1[0][i1] == "ALL" || countries[i1].indexOf(data1[i][1]) > -1) {results[i-2][i1-2] = score;}
else {results[i-2][i1-2] = 1;}
}
}
var toCopy = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("FINAL").getRange(3, 3, data1Length - 2, data1LengthHorizontal - 2); //HardCoded Starting Point
toCopy.setValues(results);
}
function aCalculator1(ws2Code) {
switch (ws2Code) {
case 3:
return 75;
case 2:
return 75;
case 1:
return 95;
case 0:
return 1;
default:
return 1;
}
}
function aCalculator2(ws2Code) {
switch (ws2Code) {
case 3:
return 10;
case 2:
return 10;
case 1:
return 10;
case 0:
return 1;
default:
return 1;
}
}
What do you think? Can you see stuff to be tweaked? How should I approach this problem? Maybe splitting chunks?
PS: Sorry If I messed up some variables while changing their names to post em.
Cheers,