Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove re-pagination from getSuggestions #2145

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions packages/bsky/src/api/app/bsky/actor/getSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,21 @@ const skeleton = async (input: {
params: Params
}): Promise<Skeleton> => {
const { ctx, params } = input
let dids: string[] = []
// @NOTE for appview swap moving to rkey-based cursors which are somewhat permissive, should not hard-break pagination
let cursor: string | undefined = params.cursor
// filter out follows and re-fetch if left with an empty page
while (dids.length === 0) {
const suggestions = await ctx.dataplane.getFollowSuggestions({
actorDid: params.viewer ?? undefined,
cursor,
limit: params.limit,
})
dids = suggestions.dids
cursor = parseString(suggestions.cursor)
if (!cursor || params.viewer === null) {
break
}
const suggestions = await ctx.dataplane.getFollowSuggestions({
actorDid: params.viewer ?? undefined,
cursor: params.cursor,
limit: params.limit,
})
let dids = suggestions.dids
if (params.viewer !== null) {
const follows = await ctx.dataplane.getActorFollowsActors({
actorDid: params.viewer,
targetDids: dids,
})
dids = dids.filter((did, i) => !follows.uris[i] && did !== params.viewer)
}
return { dids, cursor }
return { dids, cursor: parseString(suggestions.cursor) }
}

const hydration = async (input: {
Expand Down
6 changes: 3 additions & 3 deletions packages/bsky/tests/views/suggestions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@ describe('pds user search views', () => {

it('paginates', async () => {
const result1 = await agent.api.app.bsky.actor.getSuggestions(
{ limit: 1 },
{ limit: 2 },
{ headers: await network.serviceHeaders(sc.dids.carol) },
)
expect(result1.data.actors.length).toBe(1)
expect(result1.data.actors[0].handle).toEqual('bob.test')

const result2 = await agent.api.app.bsky.actor.getSuggestions(
{ limit: 1, cursor: result1.data.cursor },
{ limit: 2, cursor: result1.data.cursor },
{ headers: await network.serviceHeaders(sc.dids.carol) },
)
expect(result2.data.actors.length).toBe(1)
expect(result2.data.actors[0].handle).toEqual('dan.test')

const result3 = await agent.api.app.bsky.actor.getSuggestions(
{ limit: 1, cursor: result2.data.cursor },
{ limit: 2, cursor: result2.data.cursor },
{ headers: await network.serviceHeaders(sc.dids.carol) },
)
expect(result3.data.actors.length).toBe(0)
Expand Down
Loading