From 9c1375871a9b71acd36a6565e4a2f8a1bff0f1d2 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 3 Nov 2023 23:44:43 +0100 Subject: [PATCH] Don't bother updating the Slack mapping sheet if there are no updates. --- bin/sync.pl | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/bin/sync.pl b/bin/sync.pl index 8f2c3b0..649cfec 100644 --- a/bin/sync.pl +++ b/bin/sync.pl @@ -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) { -- 2.39.5