theoephraim / node-google-spreadsheet

Google Sheets API wrapper for Javascript / Typescript
https://theoephraim.github.io/node-google-spreadsheet
The Unlicense
2.31k stars 391 forks source link

GoogleSpreadsheetWorksheet.loadCells() really slow! #439

Closed LuisDev99 closed 2 years ago

LuisDev99 commented 3 years ago

I'm currently working on reading data from a spreadsheet but when I try to load 108 rows, each with 43 columns, it takes alot of time to load the cells into the application.

async readSpreadsheetData() {
  await this.authenticateGoogleSpreadsheet();
  await this.googleSpreadsheet.loadInfo(); 

  const sheet = this.googleSpreadsheet.sheetsByIndex[MAIN_SPREADSHEET_INDEX]; 

  console.time('loadCells benchmark');

  // For some reason, loadCells is too SLOW
  await sheet.loadCells({
    startRowIndex: 1,
    startColumnIndex: 0,
    endRowIndex: 108,
    endColumnIndex: 43,
  });

  console.timeEnd('loadCells benchmark'); // Logs 8.5+ seconds on average
}

Time results:

image

As you can see, I'm just calling loadCells but it is taking a bit of time to load the cells (above 8 seconds on average).

Is there a way to make loadCells faster? Am I doing something wrong, or is this how it is supposed to be?

I really need to load all the cells. I know that the docs says that if speed is crucial, I better go off and use the googleapi but speed isn't crucial here and I think there might be a quick workaround on this simple loadCell use case (hopefully). Maybe just by checking the amount of rows and doing a batchGet if passed a certain limit?

Anyways, thank you for this beautiful library! I would be happy to help on this.

kintut4 commented 3 years ago

hey at least you get something... i just cant get around the fucking undefined...

LuisDev99 commented 3 years ago

Maybe I can help you. Do you still have the error?

If you do, did you set the environment variables?

theoephraim commented 2 years ago

I dont think theres much that can be done for this, since the loadCells call is just calling google's API.