]> git.sesse.net Git - skvidarsync/commitdiff
Don't bother updating the Slack mapping sheet if there are no updates.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 3 Nov 2023 22:44:43 +0000 (23:44 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 3 Nov 2023 22:44:43 +0000 (23:44 +0100)
bin/sync.pl

index 8f2c3b06d19fb89d4a9268fd2963305b99488a73..649cfec71ea07078b5910ecef8a6cefaf32ae706 100644 (file)
@@ -610,19 +610,21 @@ sub run {
                        }
                }
        }
-       my $update = {
-               valueInputOption => 'USER_ENTERED',
-               data => \@slack_mapping_updates
-       };
-       $start = [Time::HiRes::gettimeofday];
-       $response = $ua->post(
-               'https://sheets.googleapis.com/v4/spreadsheets/' . $config::sheet_id . '/values:batchUpdate?key=' . $config::gsheets_api_key,
-               Content => JSON::XS::encode_json($update),
-               Content_type => 'application/json;charset=UTF-8',
-               Authorization => 'Bearer ' . $token
-       );
-       log_timing($start, "/spreadsheets/values:batchUpdate");
-       die $response->decoded_content if (!$response->is_success);
+       if (scalar @slack_mapping_updates > 0) {
+               my $update = {
+                       valueInputOption => 'USER_ENTERED',
+                       data => \@slack_mapping_updates
+               };
+               $start = [Time::HiRes::gettimeofday];
+               $response = $ua->post(
+                       'https://sheets.googleapis.com/v4/spreadsheets/' . $config::sheet_id . '/values:batchUpdate?key=' . $config::gsheets_api_key,
+                       Content => JSON::XS::encode_json($update),
+                       Content_type => 'application/json;charset=UTF-8',
+                       Authorization => 'Bearer ' . $token
+               );
+               log_timing($start, "/spreadsheets/values:batchUpdate");
+               die $response->decoded_content if (!$response->is_success);
+       }
 
        # Now that we have Slack names, we can log double-reacters.
        for my $userid (keys %double) {