diff --git a/bun.lockb b/bun.lockb index e63e129..305770b 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/src/routes/api/webhooks/google-sheets/+server.ts b/src/routes/api/webhooks/google-sheets/+server.ts index feb93a2..8d869ae 100644 --- a/src/routes/api/webhooks/google-sheets/+server.ts +++ b/src/routes/api/webhooks/google-sheets/+server.ts @@ -40,6 +40,7 @@ export const POST = async ({ request }) => { ); const existingPostsSet = new Set(); + const allPostKeywordsToInsert: { post_id: number; keyword_id: number }[] = []; if (titles.length > 0 && contacts.length > 0) { const { data: existingPosts } = await supabaseAdmin @@ -147,8 +148,8 @@ export const POST = async ({ request }) => { } if (keywordIdsToInsert.length > 0) { - await supabaseAdmin.from('postkeyword').insert( - keywordIdsToInsert.map((keywordId) => ({ + allPostKeywordsToInsert.push( + ...keywordIdsToInsert.map((keywordId) => ({ post_id: postData.id, keyword_id: keywordId })) @@ -157,6 +158,10 @@ export const POST = async ({ request }) => { } } + if (allPostKeywordsToInsert.length > 0) { + await supabaseAdmin.from('postkeyword').insert(allPostKeywordsToInsert); + } + return json({ success: true, insertedCount, skippedCount, errors }); } catch (error) { console.error('Webhook error:', error);