Improve dedupe logic on search suggestions (#1958)
parent
7c51a3931a
commit
019aae5f01
|
@ -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 = (
|
||||
const friendsOfFriends = new Map<
|
||||
string,
|
||||
AppBskyActorDefs.ProfileViewBasic
|
||||
>()
|
||||
|
||||
await Promise.all(
|
||||
friends
|
||||
.slice(0, 4)
|
||||
.map(friend =>
|
||||
getSuggestedFollowsByActor(friend.did).then(
|
||||
foafsRes => foafsRes.suggestions,
|
||||
friends.slice(0, 4).map(friend =>
|
||||
getSuggestedFollowsByActor(friend.did).then(foafsRes => {
|
||||
for (const user of foafsRes.suggestions) {
|
||||
friendsOfFriends.set(user.did, user)
|
||||
}
|
||||
}),
|
||||
),
|
||||
),
|
||||
)
|
||||
).flat()
|
||||
const deduped = friendsOfFriends.filter(
|
||||
(f, i) => friendsOfFriends.findIndex(f2 => f.did === f2.did) === i,
|
||||
)
|
||||
|
||||
setSuggestions(deduped)
|
||||
setSuggestions(Array.from(friendsOfFriends.values()))
|
||||
setDataUpdatedAt(Date.now())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue