a tool for shared writing and social publishing

add indexed col to documents and update inngest

+52 -32
+2 -2
app/api/inngest/client.ts
··· 51 51 documentUris?: string[]; 52 52 }; 53 53 }; 54 - "appview/sync-bsky-likes": { 54 + "appview/sync-document-metadata": { 55 55 data: { 56 56 document_uri: string; 57 - bsky_post_uri: string; 57 + bsky_post_uri?: string; 58 58 }; 59 59 }; 60 60 "user/write-records-to-pds": {
+20 -10
app/api/inngest/functions/sync_bsky_likes.ts app/api/inngest/functions/sync_document_metadata.ts
··· 5 5 6 6 const TOTAL_ITERATIONS = 144; // 36 hours at 15-minute intervals 7 7 8 - export const sync_bsky_likes = inngest.createFunction( 8 + export const sync_document_metadata = inngest.createFunction( 9 9 { 10 - id: "sync_bsky_likes", 11 - idempotency: "event.data.bsky_post_uri", 10 + id: "sync_document_metadata", 11 + idempotency: "event.data.document_uri", 12 12 }, 13 - { event: "appview/sync-bsky-likes" }, 13 + { event: "appview/sync-document-metadata" }, 14 14 async ({ event, step }) => { 15 15 const { document_uri, bsky_post_uri } = event.data; 16 16 17 - const isBridgy = await step.run("check-bridgy", async () => { 18 - const did = new AtUri(bsky_post_uri).host; 17 + const did = new AtUri(document_uri).host; 18 + 19 + const handleResult = await step.run("resolve-handle", async () => { 19 20 const doc = await idResolver.did.resolve(did); 20 21 const handle = doc?.alsoKnownAs 21 22 ?.find((a) => a.startsWith("at://")) 22 23 ?.replace("at://", ""); 23 - return handle?.includes("brid.gy") ?? false; 24 + return { handle: handle ?? null, isBridgy: handle?.includes("brid.gy") ?? false }; 24 25 }); 25 26 26 - if (isBridgy) { 27 - return { skipped: true, reason: "brid.gy post" }; 27 + if (handleResult.isBridgy) { 28 + await step.run("set-unindexed", async () => { 29 + await supabaseServerClient 30 + .from("documents") 31 + .update({ indexed: false }) 32 + .eq("uri", document_uri); 33 + }); 34 + } 35 + 36 + if (!bsky_post_uri || handleResult.isBridgy) { 37 + return { handle: handleResult.handle }; 28 38 } 29 39 30 40 const agent = new AtpAgent({ service: "https://public.api.bsky.app" }); ··· 50 60 likeCount = await step.run(`sync-${i}`, fetchAndUpdate); 51 61 } 52 62 53 - return { likeCount }; 63 + return { likeCount, handle: handleResult.handle }; 54 64 }, 55 65 );
+2 -2
app/api/inngest/route.tsx
··· 13 13 check_oauth_session, 14 14 } from "./functions/cleanup_expired_oauth_sessions"; 15 15 import { write_records_to_pds } from "./functions/write_records_to_pds"; 16 - import { sync_bsky_likes } from "./functions/sync_bsky_likes"; 16 + import { sync_document_metadata } from "./functions/sync_document_metadata"; 17 17 18 18 export const { GET, POST, PUT } = serve({ 19 19 client: inngest, ··· 29 29 cleanup_expired_oauth_sessions, 30 30 check_oauth_session, 31 31 write_records_to_pds, 32 - sync_bsky_likes, 32 + sync_document_metadata, 33 33 ], 34 34 });
+14 -18
appview/index.ts
··· 109 109 data: record.value as Json, 110 110 }); 111 111 if (docResult.error) console.log(docResult.error); 112 - if (record.value.postRef?.uri) { 113 - await inngest.send({ 114 - name: "appview/sync-bsky-likes", 115 - data: { 116 - document_uri: evt.uri.toString(), 117 - bsky_post_uri: record.value.postRef.uri, 118 - }, 119 - }); 120 - } 112 + await inngest.send({ 113 + name: "appview/sync-document-metadata", 114 + data: { 115 + document_uri: evt.uri.toString(), 116 + bsky_post_uri: record.value.postRef?.uri, 117 + }, 118 + }); 121 119 if (record.value.publication) { 122 120 let publicationURI = new AtUri(record.value.publication); 123 121 ··· 278 276 data: record.value as Json, 279 277 }); 280 278 if (docResult.error) console.log(docResult.error); 281 - if (record.value.bskyPostRef?.uri) { 282 - await inngest.send({ 283 - name: "appview/sync-bsky-likes", 284 - data: { 285 - document_uri: evt.uri.toString(), 286 - bsky_post_uri: record.value.bskyPostRef.uri, 287 - }, 288 - }); 289 - } 279 + await inngest.send({ 280 + name: "appview/sync-document-metadata", 281 + data: { 282 + document_uri: evt.uri.toString(), 283 + bsky_post_uri: record.value.bskyPostRef?.uri, 284 + }, 285 + }); 290 286 291 287 // site.standard.document uses "site" field to reference the publication 292 288 // For documents in publications, site is an AT-URI (at://did:plc:xxx/site.standard.publication/rkey)
+8
supabase/database.types.ts
··· 337 337 Row: { 338 338 bsky_like_count: number 339 339 data: Json 340 + indexed: boolean 340 341 indexed_at: string 342 + recommend_count: number 341 343 sort_date: string 342 344 uri: string 343 345 } 344 346 Insert: { 345 347 bsky_like_count?: number 346 348 data: Json 349 + indexed?: boolean 347 350 indexed_at?: string 351 + recommend_count?: number 352 + sort_date?: string 348 353 uri: string 349 354 } 350 355 Update: { 351 356 bsky_like_count?: number 352 357 data?: Json 358 + indexed?: boolean 353 359 indexed_at?: string 360 + recommend_count?: number 361 + sort_date?: string 354 362 uri?: string 355 363 } 356 364 Relationships: []
+6
supabase/migrations/20260210100000_add_indexed_column_and_ranking_index.sql
··· 1 + ALTER TABLE documents ADD COLUMN indexed boolean NOT NULL DEFAULT true; 2 + 3 + CREATE INDEX idx_documents_ranking 4 + ON documents (sort_date DESC) 5 + INCLUDE (uri, bsky_like_count, recommend_count) 6 + WHERE indexed = true;