a tool for shared writing and social publishing
1import { supabaseServerClient } from "supabase/serverClient";
2import { inngest } from "../client";
3
4export const batched_update_profiles = inngest.createFunction(
5 {
6 id: "batched_update_profiles",
7 batchEvents: {
8 maxSize: 100,
9 timeout: "10s",
10 },
11 },
12 { event: "appview/profile-update" },
13 async ({ events, step }) => {
14 let existingProfiles = await supabaseServerClient
15 .from("bsky_profiles")
16 .select("did")
17 .in(
18 "did",
19 events.map((event) => event.data.did),
20 );
21 if (!existingProfiles.data) return { error: existingProfiles.error };
22
23 const profileUpdates = events.map((event) => ({
24 did: event.data.did,
25 record: event.data.record,
26 }));
27
28 let { error } = await supabaseServerClient
29 .from("bsky_profiles")
30 .upsert(profileUpdates);
31 return {
32 done: true,
33 profiles_updated: existingProfiles.data.length,
34 error,
35 };
36 },
37);