Skip to content

Commit 2e16995

Browse files
committed
Update batch size and maximum concurrent requests for meeting summaries retrieval
1 parent e0670d6 commit 2e16995

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

netlify/functions/batchUpdateMeetingSummariesById.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
import { supabase } from '../../lib/supabaseClient';
33
import { Octokit } from "@octokit/rest";
44

5-
const BATCH_SIZE = 200;
6-
const MAX_CONCURRENT_REQUESTS = 5;
5+
const BATCH_SIZE = 100;
6+
const MAX_CONCURRENT_REQUESTS = 10;
77

8-
async function fetchMeetingSummaries(lastProcessedTimestamp) {
8+
async function fetchMeetingSummaries(lastProcessedTimestamp, batchNumber) {
99
const { data: summaries, error } = await supabase
1010
.from('meetingsummaries')
1111
.select('created_at, meeting_id, summary')
1212
.eq('confirmed', true)
1313
.order('created_at', { ascending: true })
14-
.limit(BATCH_SIZE * MAX_CONCURRENT_REQUESTS)
15-
.gt('created_at', lastProcessedTimestamp || '1970-01-01');
14+
.limit(BATCH_SIZE)
15+
.gt('created_at', lastProcessedTimestamp || '1970-01-01')
16+
.range(batchNumber * BATCH_SIZE, (batchNumber + 1) * BATCH_SIZE - 1);
1617

1718
if (error) {
1819
throw new Error('Failed to retrieve meeting summaries');
1920
}
20-
2121
return summaries;
2222
}
2323

@@ -74,17 +74,29 @@ async function processAndCommitSummaries() {
7474
const allSummaries = {};
7575
let lastProcessedTimestamp = null;
7676
let hasMoreSummaries = true;
77+
let batchNumber = 0;
7778

7879
while (hasMoreSummaries) {
79-
const summaries = await fetchMeetingSummaries(lastProcessedTimestamp);
80+
const fetchPromises = [];
81+
82+
for (let i = 0; i < MAX_CONCURRENT_REQUESTS; i++) {
83+
fetchPromises.push(fetchMeetingSummaries(lastProcessedTimestamp, batchNumber));
84+
batchNumber++;
85+
}
8086

81-
if (summaries.length === 0) {
87+
const summariesBatches = await Promise.all(fetchPromises);
88+
const flattenedSummaries = summariesBatches.flat();
89+
90+
if (flattenedSummaries.length === 0) {
8291
hasMoreSummaries = false;
8392
break;
8493
}
8594

86-
groupSummariesByMeetingId(summaries, allSummaries);
87-
lastProcessedTimestamp = summaries[summaries.length - 1].created_at;
95+
flattenedSummaries.forEach(summary => {
96+
groupSummariesByMeetingId([summary], allSummaries);
97+
});
98+
99+
lastProcessedTimestamp = flattenedSummaries[flattenedSummaries.length - 1].created_at;
88100
}
89101

90102
await commitSummariesToGitHub(allSummaries);

0 commit comments

Comments
 (0)