|
2 | 2 | import { supabase } from '../../lib/supabaseClient'; |
3 | 3 | import { Octokit } from "@octokit/rest"; |
4 | 4 |
|
5 | | -const BATCH_SIZE = 200; |
6 | | -const MAX_CONCURRENT_REQUESTS = 5; |
| 5 | +const BATCH_SIZE = 100; |
| 6 | +const MAX_CONCURRENT_REQUESTS = 10; |
7 | 7 |
|
8 | | -async function fetchMeetingSummaries(lastProcessedTimestamp) { |
| 8 | +async function fetchMeetingSummaries(lastProcessedTimestamp, batchNumber) { |
9 | 9 | const { data: summaries, error } = await supabase |
10 | 10 | .from('meetingsummaries') |
11 | 11 | .select('created_at, meeting_id, summary') |
12 | 12 | .eq('confirmed', true) |
13 | 13 | .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); |
16 | 17 |
|
17 | 18 | if (error) { |
18 | 19 | throw new Error('Failed to retrieve meeting summaries'); |
19 | 20 | } |
20 | | - |
21 | 21 | return summaries; |
22 | 22 | } |
23 | 23 |
|
@@ -74,17 +74,29 @@ async function processAndCommitSummaries() { |
74 | 74 | const allSummaries = {}; |
75 | 75 | let lastProcessedTimestamp = null; |
76 | 76 | let hasMoreSummaries = true; |
| 77 | + let batchNumber = 0; |
77 | 78 |
|
78 | 79 | 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 | + } |
80 | 86 |
|
81 | | - if (summaries.length === 0) { |
| 87 | + const summariesBatches = await Promise.all(fetchPromises); |
| 88 | + const flattenedSummaries = summariesBatches.flat(); |
| 89 | + |
| 90 | + if (flattenedSummaries.length === 0) { |
82 | 91 | hasMoreSummaries = false; |
83 | 92 | break; |
84 | 93 | } |
85 | 94 |
|
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; |
88 | 100 | } |
89 | 101 |
|
90 | 102 | await commitSummariesToGitHub(allSummaries); |
|
0 commit comments