data endpoint for entity 90008 (aka. a website)
0
fork

Configure Feed

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

feat: fetch guestbook replies in parallel

dusk 43c23359 44525e92

+13 -11
+13 -11
src/routes/guestbook/+page.server.ts
··· 7 7 import { nanoid } from 'nanoid'; 8 8 import { noteFromBskyPost, type NoteData } from '../../components/note.svelte'; 9 9 import { get, writable } from 'svelte/store'; 10 + import type { Post } from '@skyware/bot'; 10 11 11 12 export const prerender = false; 12 13 ··· 109 110 // actually get posts 110 111 try { 111 112 const { posts } = await getUserPosts('did:web:guestbook.gaze.systems', 16); 112 - for (const post of posts) { 113 + const fetchPostReplies = async (post: Post) => { 114 + if ((post.replyCount ?? 0) === 0) return { post, replies: [] }; 115 + return { post, replies: await post.fetchChildren({ depth: 1, force: true }) }; 116 + }; 117 + const postsWithReplies = await Promise.all(posts.map(fetchPostReplies)); 118 + for (const { post, replies } of postsWithReplies) { 113 119 const note = noteFromBskyPost(post); 114 - // the only reply can be mine 115 - if (post.replyCount ?? 0 > 0) { 116 - const replies = await post.fetchChildren({ depth: 1, force: true }); 117 - note.children = replies.map((reply) => { 118 - const note = noteFromBskyPost(reply); 119 - note.purposeAction = 'reply'; 120 - note.outgoingLinks = [{ name: 'bsky-reply', link: reply.uri }]; 121 - return note; 122 - }); 123 - } 120 + note.children = replies.map((reply) => { 121 + const replyNote = noteFromBskyPost(reply); 122 + replyNote.purposeAction = 'reply'; 123 + replyNote.outgoingLinks = [{ name: 'bsky-reply', link: reply.uri }]; 124 + return replyNote; 125 + }); 124 126 data.entries.push(note); 125 127 } 126 128 // eslint-disable-next-line @typescript-eslint/no-explicit-any