Skip to content

Commit

Permalink
Improve dedupe logic on search suggestions (#1958)
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey authored Nov 17, 2023
1 parent 7c51a39 commit 019aae5
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/view/screens/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,29 +119,28 @@ function SearchScreenSuggestedFollows() {

React.useEffect(() => {
async function getSuggestions() {
// TODO not quite right, doesn't fetch your follows
const friends = await getSuggestedFollowsByActor(
currentAccount!.did,
).then(friendsRes => friendsRes.suggestions)

if (!friends) return // :(

const friendsOfFriends = (
await Promise.all(
friends
.slice(0, 4)
.map(friend =>
getSuggestedFollowsByActor(friend.did).then(
foafsRes => foafsRes.suggestions,
),
),
)
).flat()
const deduped = friendsOfFriends.filter(
(f, i) => friendsOfFriends.findIndex(f2 => f.did === f2.did) === i,
const friendsOfFriends = new Map<
string,
AppBskyActorDefs.ProfileViewBasic
>()

await Promise.all(
friends.slice(0, 4).map(friend =>
getSuggestedFollowsByActor(friend.did).then(foafsRes => {
for (const user of foafsRes.suggestions) {
friendsOfFriends.set(user.did, user)
}
}),
),
)

setSuggestions(deduped)
setSuggestions(Array.from(friendsOfFriends.values()))
setDataUpdatedAt(Date.now())
}

Expand Down

0 comments on commit 019aae5

Please sign in to comment.