Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

googlesheets: don't run update or append if there is no data #576

Open
josephjclark opened this issue May 22, 2024 · 1 comment · May be fixed by #927
Open

googlesheets: don't run update or append if there is no data #576

josephjclark opened this issue May 22, 2024 · 1 comment · May be fixed by #927

Comments

@josephjclark
Copy link
Collaborator

josephjclark commented May 22, 2024

It might be useful sometimes to use the write API in a no-op way. This is quite functional programming-ish and would align well with our job code - you can safely pass no data into appendValues and it'll happily do nothing. This saves us an if statement.

If the values to appendValues or batchUpdateValues are nullish or empty, we should not call out the google API and return early. Maybe we should log a message saying skipping appendValues as no data passed or something.

Example job:

getValues(
  '18129',
  'mtuchi-testing!A:AD',
  state => {
    const {
      taskId,
      data: { values },
    } = state;

    const rowIndex = values.findIndex(row => row['0'] === taskId);

    if (rowIndex !== -1) {
       state.updateRange = `mtuchi-testing!A${rowIndex + 1}:AD${rowIndex + 1}`;
       state.toAppend = state.gsheetValues;
       state.toUpsert = [];
    } else {
       state.updateRange =  'mtuchi-testing!A2:AD2';
       state.toAppend= [];
       state.toUpsert= state.gsheetValues;
   }

    return state;
  }
);

batchUpdateValues({
      spreadsheetId: '18129',
      range: $.updateRange,
      values: $.toUpdate,
 })

appendValues({
  spreadsheetId: '18129',
      range: $.updateRange,
  values: $.toAppend
})
@github-project-automation github-project-automation bot moved this to New Issues in v2 May 22, 2024
@christad92 christad92 moved this from New Issues to Backlog in v2 Jun 11, 2024
@josephjclark
Copy link
Collaborator Author

Hi @PiusKariuki - maybe you could take a look at this one?

Is the issue is clear? The problem is (I think) that if you try and do appendValues() but pass an empty array (or maybe an undefined/null value), you'll get an error.

This means that users have to do fnIf() now to maybe send data to sheets, but this is needlessly awkward.

@PiusKariuki PiusKariuki linked a pull request Jan 18, 2025 that will close this issue
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

Successfully merging a pull request may close this issue.

1 participant