a tool for shared writing and social publishing

use supabase pool instead of pg and run identity check in parralel

+20 -15
+20 -15
app/api/inngest/functions/index_follows.ts
··· 3 import { createIdentity } from "actions/createIdentity"; 4 import { drizzle } from "drizzle-orm/node-postgres"; 5 import { inngest } from "../client"; 6 - import { Client } from "pg"; 7 8 export const index_follows = inngest.createFunction( 9 { ··· 45 cursor = page.cursor || null; 46 if (!cursor) hasMore = false; 47 } 48 - await step.run("check-if-identity-exists", async () => { 49 - let { data: exists } = await supabaseServerClient 50 - .from("identities") 51 - .select() 52 - .eq("atp_did", event.data.did); 53 - if (!exists) { 54 - let client = new Client({ connectionString: process.env.DB_URL }); 55 - let db = drizzle(client); 56 - await createIdentity(db, { atp_did: event.data.did }); 57 - client.end(); 58 - } 59 - }); 60 let existingFollows: string[] = []; 61 const batchSize = 100; 62 let batchNumber = 0; 63 64 // Create all check batches in parallel 65 - const checkBatches = []; 66 for (let i = 0; i < follows.length; i += batchSize) { 67 const batch = follows.slice(i, i + batchSize); 68 checkBatches.push( ··· 104 follows: f, 105 })); 106 107 - await supabaseServerClient.from("bsky_follows").upsert(insertData); 108 }), 109 ); 110 insertBatchNumber++;
··· 3 import { createIdentity } from "actions/createIdentity"; 4 import { drizzle } from "drizzle-orm/node-postgres"; 5 import { inngest } from "../client"; 6 + import { pool } from "supabase/pool"; 7 8 export const index_follows = inngest.createFunction( 9 { ··· 45 cursor = page.cursor || null; 46 if (!cursor) hasMore = false; 47 } 48 let existingFollows: string[] = []; 49 const batchSize = 100; 50 let batchNumber = 0; 51 52 // Create all check batches in parallel 53 + const checkBatches: Promise<any>[] = [ 54 + step.run("check-if-identity-exists", async () => { 55 + let { data: exists } = await supabaseServerClient 56 + .from("identities") 57 + .select() 58 + .eq("atp_did", event.data.did) 59 + .single(); 60 + if (!exists) { 61 + const client = await pool.connect(); 62 + let db = drizzle(client); 63 + let identity = await createIdentity(db, { atp_did: event.data.did }); 64 + client.release(); 65 + return identity; 66 + } 67 + }), 68 + ]; 69 for (let i = 0; i < follows.length; i += batchSize) { 70 const batch = follows.slice(i, i + batchSize); 71 checkBatches.push( ··· 107 follows: f, 108 })); 109 110 + return await supabaseServerClient 111 + .from("bsky_follows") 112 + .upsert(insertData); 113 }), 114 ); 115 insertBatchNumber++;