a tool for shared writing and social publishing
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

batch profile updates

+52 -5
+6
app/api/inngest/client.ts
··· 3 3 import { EventSchemas } from "inngest"; 4 4 5 5 export type Events = { 6 + "appview/profile-update": { 7 + data: { 8 + record: any; 9 + did: string; 10 + }; 11 + }; 6 12 "appview/index-bsky-post-mention": { 7 13 data: { 8 14 post_uri: string;
+37
app/api/inngest/functions/batched_update_profiles.ts
··· 1 + import { supabaseServerClient } from "supabase/serverClient"; 2 + import { inngest } from "../client"; 3 + 4 + export 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 + );
+2 -1
app/api/inngest/route.tsx
··· 2 2 import { inngest } from "app/api/inngest/client"; 3 3 import { index_post_mention } from "./functions/index_post_mention"; 4 4 import { come_online } from "./functions/come_online"; 5 + import { batched_update_profiles } from "./functions/batched_update_profiles"; 5 6 6 7 // Create an API that serves zero functions 7 8 export const { GET, POST, PUT } = serve({ 8 9 client: inngest, 9 - functions: [index_post_mention, come_online], 10 + functions: [index_post_mention, come_online, batched_update_profiles], 10 11 });
+7 -4
appview/index.ts
··· 138 138 if (evt.collection === ids.AppBskyActorProfile) { 139 139 //only listen to updates because we should fetch it for the first time when they subscribe! 140 140 if (evt.event === "update") { 141 - await supabaseServerClient 142 - .from("bsky_profiles") 143 - .update({ record: evt.record as Json }) 144 - .eq("did", evt.did); 141 + await inngest.send({ 142 + name: "appview/profile-update", 143 + data: { 144 + did: evt.did, 145 + record: evt.record, 146 + }, 147 + }); 145 148 } 146 149 } 147 150 if (evt.collection === "app.bsky.feed.post") {