Skip to content

Commit

Permalink
Enforce feed limit before hydration (#2935)
Browse files Browse the repository at this point in the history
* Enforce feed limit before hydration

* Remove limit margin
  • Loading branch information
rafaelbsky authored Nov 1, 2024
1 parent e680d55 commit 512585a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/bsky/src/api/app/bsky/feed/getFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,22 @@ const noBlocksOrMutes = (inputs: RulesFnInput<Context, Params, Skeleton>) => {
!bam.ancestorAuthorBlocked
)
})

return skeleton
}

const presentation = (
inputs: PresentationFnInput<Context, Params, Skeleton>,
) => {
const { ctx, params, skeleton, hydration } = inputs
const { ctx, skeleton, hydration } = inputs
const feed = mapDefined(skeleton.items, (item) => {
const post = ctx.views.feedViewPost(item, hydration)
if (!post) return
return {
...post,
feedContext: item.feedContext,
}
}).slice(0, params.limit)
})
return {
feed,
cursor: skeleton.cursor,
Expand Down Expand Up @@ -211,6 +212,7 @@ const skeletonFromFeedGen = async (
const result = await agent.api.app.bsky.feed.getFeedSkeleton(
{
feed: params.feed,
// The feedgen is not guaranteed to honor the limit, but we try it.
limit: params.limit,
cursor: params.cursor,
},
Expand Down Expand Up @@ -243,7 +245,7 @@ const skeletonFromFeedGen = async (
}

const { feed: feedSkele, ...skele } = skeleton
const feedItems = feedSkele.map((item) => ({
const feedItems = feedSkele.slice(0, params.limit).map((item) => ({
post: { uri: item.post },
repost:
typeof item.reason?.repost === 'string'
Expand Down

0 comments on commit 512585a

Please sign in to comment.