Skip to content

Commit 1246a69

Browse files
committed
Refactor meeting summaries retrieval and commit process
1 parent c6f05d9 commit 1246a69

File tree

1 file changed

+14
-33
lines changed

1 file changed

+14
-33
lines changed

netlify/functions/batchUpdateMeetingSummariesArray.js

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

5-
const BATCH_SIZE = 100;
6-
75
export const handler = async (event, context) => {
86
try {
9-
let allSummaries = [];
10-
let lastProcessedTimestamp = null;
11-
let hasMoreSummaries = true;
12-
13-
while (hasMoreSummaries) {
14-
// Retrieve the next batch of summaries
15-
let { data: summaries, error } = await supabase
16-
.from('meetingsummaries')
17-
.select('meeting_id, created_at, summary')
18-
.order('created_at', { ascending: true })
19-
.limit(BATCH_SIZE);
7+
// Retrieve all summaries
8+
const { data: summaries, error } = await supabase
9+
.from('meetingsummaries')
10+
.select('meeting_id, created_at, summary')
11+
.order('created_at', { ascending: true });
2012

21-
if (lastProcessedTimestamp) {
22-
summaries = summaries.filter(summary => summary.created_at > lastProcessedTimestamp);
23-
}
24-
25-
if (error) {
26-
console.error('Error retrieving meeting summaries:', error);
27-
return {
28-
statusCode: 500,
29-
body: JSON.stringify({ error: 'Failed to retrieve meeting summaries' }),
30-
};
31-
}
32-
33-
if (summaries.length === 0) {
34-
hasMoreSummaries = false;
35-
break;
36-
}
37-
38-
// Accumulate the summaries
39-
allSummaries = allSummaries.concat(summaries.map(summary => summary.summary));
40-
lastProcessedTimestamp = summaries[summaries.length - 1].created_at;
13+
if (error) {
14+
console.error('Error retrieving meeting summaries:', error);
15+
return {
16+
statusCode: 500,
17+
body: JSON.stringify({ error: 'Failed to retrieve meeting summaries' }),
18+
};
4119
}
4220

21+
// Extract summaries from the retrieved data
22+
const allSummaries = summaries.map(summary => summary.summary);
23+
4324
// Commit all summaries to GitHub in a single file
4425
const octokit = new Octokit({
4526
auth: process.env.GITHUB_TOKEN,

0 commit comments

Comments
 (0)