}
sub get_spreadsheet_with_title {
- my ($ua, $token, $wanted_sheet_title) = @_;
+ my ($dbh, $ua, $token, $invitation_ts, $wanted_sheet_title) = @_;
# See if we have any spreadsheets that match this title.
my $start = [Time::HiRes::gettimeofday];
my $sheet_id = $sheet->{'properties'}{'sheetId'};
if ($title =~ /\Q$wanted_sheet_title\E/) {
# skv_log("Synkroniserer ($config::invitation_channel, $invitation_ts) mot arket “$title” (fane-ID $sheet_id).");
+ $dbh->do('UPDATE message_sheet_link SET tab_name=?, tab_id=? WHERE channel=? AND ts=?',
+ undef, $title, $sheet_id, $config::invitation_channel, $invitation_ts);
return ($title, $sheet_id);
}
}
my $invitation_ts = $linkref->{'ts'};
my $wanted_sheet_title = $linkref->{'sheet_title'};
die "Could not get newest sheet title" if (!defined($wanted_sheet_title));
-
- my ($tab_name, $tab_id) = get_spreadsheet_with_title($ua, $token, $wanted_sheet_title);
- if (!defined($tab_name)) {
- skv_log("Fant ikke noen fane med «$wanted_sheet_title» i navnet; kan ikke synkronisere.\n");
- sheet_batch_update($ua, $token, [ serialize_skv_log_to_sheet() ]);
- die;
- }
+ my $tab_name = $linkref->{'tab_name'};
+ my $tab_id = $linkref->{'tab_id'};
# Store away the second-newest ID.
my $prev_invitation_ts = $q->fetchrow_hashref->{'ts'};
+ if (!defined($tab_name) || !defined($tab_id)) {
+ ($tab_name, $tab_id) = get_spreadsheet_with_title($dbh, $ua, $token, $invitation_ts, $wanted_sheet_title);
+ if (!defined($tab_name)) {
+ skv_log("Fant ikke noen fane med «$wanted_sheet_title» i navnet; kan ikke synkronisere.\n");
+ sheet_batch_update($ua, $token, [ serialize_skv_log_to_sheet() ]);
+ die;
+ }
+ }
+
# Find everyone who are marked as attending on Slack (via reactions).
$q = $dbh->prepare('SELECT DISTINCT userid,reaction FROM current_reactions WHERE channel=? AND ts=? AND reaction IN (\'heart\', \'open_mouth\', \'blue_heart\')');
$q->execute($config::invitation_channel, $invitation_ts);
print STDERR "Matching message {$channel, $ts} to date $date\n";
$dbh->do('INSERT INTO message_sheet_link (channel, ts, sheet_title) VALUES (?,?,?)', undef,
$channel, $ts, $date);
+ # Blow the cache.
+ $dbh->do('UPDATE message_sheet_link SET tab_name=NULL, tab_id=NULL WHERE channel=?', undef, $channel);
} else {
print STDERR "No date found in message, ignoring\n";
}