Retro Bulletin Board Systems on atproto. Web app and TUI. lazy mirror of alyraffauf/atbbs atbbs.xyz
forums python tui atproto bbs
3
fork

Configure Feed

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

web/sysop: batch fetches for hidden posts

+24 -16
+24 -16
web/src/router/loaders/sysop.ts
··· 4 4 getRecordByUri, 5 5 listRecords, 6 6 resolveIdentitiesBatch, 7 - resolveIdentity, 8 7 } from "../../lib/atproto"; 9 8 import { BAN, HIDE } from "../../lib/lexicon"; 10 9 import { parseAtUri } from "../../lib/util"; ··· 35 34 } 36 35 37 36 async function hydrateHiddenPosts(uris: Set<string>): Promise<HiddenInfo[]> { 38 - const hidden: HiddenInfo[] = []; 39 - for (const uri of uris) { 37 + if (uris.size === 0) return []; 38 + 39 + const uriList = [...uris]; 40 + const dids = [...new Set(uriList.map((uri) => parseAtUri(uri).did))]; 41 + 42 + const [identities, records] = await Promise.all([ 43 + resolveIdentitiesBatch(dids), 44 + Promise.allSettled(uriList.map(getRecordByUri)), 45 + ]); 46 + 47 + return uriList.map((uri, index) => { 40 48 const did = parseAtUri(uri).did; 41 - let handle = did; 42 - try { 43 - handle = (await resolveIdentity(did)).handle; 44 - } catch {} 45 - try { 46 - const record = await getRecordByUri(uri); 47 - const value = record.value as unknown as { title?: string; body?: string }; 48 - hidden.push({ 49 + const handle = identities[did]?.handle ?? did; 50 + const result = records[index]; 51 + 52 + if (result.status === "fulfilled") { 53 + const value = result.value.value as unknown as { 54 + title?: string; 55 + body?: string; 56 + }; 57 + return { 49 58 uri, 50 59 handle, 51 60 title: value.title ?? "", 52 61 body: (value.body ?? "").substring(0, 100), 53 - }); 54 - } catch { 55 - hidden.push({ uri, handle, title: "", body: uri }); 62 + }; 56 63 } 57 - } 58 - return hidden; 64 + 65 + return { uri, handle, title: "", body: uri }; 66 + }); 59 67 } 60 68 61 69 export async function sysopEditLoader() {