From 167dede6b1079a490b3731f4e74005c3dd946964 Mon Sep 17 00:00:00 2001 From: Devin Ivy Date: Tue, 6 Feb 2024 21:09:20 -0500 Subject: [PATCH 1/2] remove re-pagination from getSuggestions --- .../src/api/app/bsky/actor/getSuggestions.ts | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/packages/bsky/src/api/app/bsky/actor/getSuggestions.ts b/packages/bsky/src/api/app/bsky/actor/getSuggestions.ts index 6914a36d067..622fcd3891c 100644 --- a/packages/bsky/src/api/app/bsky/actor/getSuggestions.ts +++ b/packages/bsky/src/api/app/bsky/actor/getSuggestions.ts @@ -34,28 +34,21 @@ const skeleton = async (input: { params: Params }): Promise => { 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: { From ddc32d441a2a6187a48ec35faca38f562de05bf9 Mon Sep 17 00:00:00 2001 From: Devin Ivy Date: Tue, 6 Feb 2024 21:30:10 -0500 Subject: [PATCH 2/2] fix test --- packages/bsky/tests/views/suggestions.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/bsky/tests/views/suggestions.test.ts b/packages/bsky/tests/views/suggestions.test.ts index 70c153a3a56..49bc5858a34 100644 --- a/packages/bsky/tests/views/suggestions.test.ts +++ b/packages/bsky/tests/views/suggestions.test.ts @@ -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)