a tool for shared writing and social publishing
298
fork

Configure Feed

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

fetch data for all bsky posts in batches of 25

+32 -20
+32 -20
app/lish/[did]/[publication]/[rkey]/page.tsx
··· 96 96 </div> 97 97 ); 98 98 let record = document.data as PubLeafletDocument.Record; 99 - let bskyPosts = record.pages.flatMap((p) => { 100 - let page = p as PubLeafletPagesLinearDocument.Main; 101 - return page.blocks?.filter( 102 - (b) => b.block.$type === ids.PubLeafletBlocksBskyPost, 103 - ); 104 - }); 99 + let bskyPosts = 100 + record.pages.flatMap((p) => { 101 + let page = p as PubLeafletPagesLinearDocument.Main; 102 + return page.blocks?.filter( 103 + (b) => b.block.$type === ids.PubLeafletBlocksBskyPost, 104 + ); 105 + }) || []; 106 + 107 + // Batch bsky posts into groups of 25 and fetch in parallel 108 + let bskyPostBatches = []; 109 + for (let i = 0; i < bskyPosts.length; i += 25) { 110 + bskyPostBatches.push(bskyPosts.slice(i, i + 25)); 111 + } 112 + 113 + let bskyPostResponses = await Promise.all( 114 + bskyPostBatches.map((batch) => 115 + agent.getPosts( 116 + { 117 + uris: batch.map((p) => { 118 + let block = p?.block as PubLeafletBlocksBskyPost.Main; 119 + return block.postRef.uri; 120 + }), 121 + }, 122 + { headers: {} }, 123 + ), 124 + ), 125 + ); 126 + 105 127 let bskyPostData = 106 - bskyPosts.length > 0 107 - ? await agent.getPosts( 108 - { 109 - uris: bskyPosts 110 - .map((p) => { 111 - let block = p?.block as PubLeafletBlocksBskyPost.Main; 112 - return block.postRef.uri; 113 - }) 114 - .slice(0, 24), 115 - }, 116 - { headers: {} }, 117 - ) 118 - : { data: { posts: [] } }; 128 + bskyPostResponses.length > 0 129 + ? bskyPostResponses.flatMap((response) => response.data.posts) 130 + : []; 119 131 120 132 // Extract poll blocks and fetch vote data 121 133 let pollBlocks = record.pages.flatMap((p) => { ··· 172 184 pubRecord={pubRecord} 173 185 profile={JSON.parse(JSON.stringify(profile.data))} 174 186 document={document} 175 - bskyPostData={bskyPostData.data.posts} 187 + bskyPostData={bskyPostData} 176 188 did={did} 177 189 blocks={blocks} 178 190 prerenderedCodeBlocks={prerenderedCodeBlocks}