Skip to content

Commit

Permalink
Make fill debate speaker IDs work on 100-row batches (fill_debate_spe…
Browse files Browse the repository at this point in the history
…aker_ids_updated_at support)
  • Loading branch information
limdingwen committed Aug 1, 2024
1 parent c42ccd7 commit 4df4bd7
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions supabase/functions/lib/shared-functions/fill-debate-speaker-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import { SupabaseClient } from "https://esm.sh/v135/@supabase/[email protected]
async function getDebateSpeechRows(supabase: SupabaseClient) {
const { data, error } = await supabase
.from("debate_speech")
.select("id, speaker_name")
.is("speaker_id", null);
.select("id, speaker_name, fill_debate_speaker_ids_updated_at")
.is("speaker_id", null)
// Update the earliest-updated ones first
.order("fill_debate_speaker_ids_updated_at", { ascending: true })
// Just make it explicit; Supabase already limits to 1000 by default
.limit(100);
if (error) throw error;
return data;
}
Expand All @@ -33,7 +37,10 @@ async function updateDebateSpeechRowWithSpeakerId(
) {
const { error } = await supabase
.from("debate_speech")
.update({ speaker_id: speakerId })
.update({
speaker_id: speakerId,
fill_debate_speaker_ids_updated_at: new Date(),
})
.eq("id", rowId);
if (error) throw error;
}
Expand All @@ -58,10 +65,8 @@ export default async function fillDebateSpeakerIds(req: Request) {
row.speaker_name,
);

// We assume that we are only working with speakerId = null rows, so if speakerId is still null,
// don't bother updating it.
await updateDebateSpeechRowWithSpeakerId(supabase, row.id, speakerId);
if (speakerId) {
await updateDebateSpeechRowWithSpeakerId(supabase, row.id, speakerId);
rowCount++;
}

Expand Down

0 comments on commit 4df4bd7

Please sign in to comment.