Improve dedupe logic on search suggestions (#1958)
parent
7c51a3931a
commit
019aae5f01
|
@ -119,29 +119,28 @@ function SearchScreenSuggestedFollows() {
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
async function getSuggestions() {
|
async function getSuggestions() {
|
||||||
// TODO not quite right, doesn't fetch your follows
|
|
||||||
const friends = await getSuggestedFollowsByActor(
|
const friends = await getSuggestedFollowsByActor(
|
||||||
currentAccount!.did,
|
currentAccount!.did,
|
||||||
).then(friendsRes => friendsRes.suggestions)
|
).then(friendsRes => friendsRes.suggestions)
|
||||||
|
|
||||||
if (!friends) return // :(
|
if (!friends) return // :(
|
||||||
|
|
||||||
const friendsOfFriends = (
|
const friendsOfFriends = new Map<
|
||||||
await Promise.all(
|
string,
|
||||||
friends
|
AppBskyActorDefs.ProfileViewBasic
|
||||||
.slice(0, 4)
|
>()
|
||||||
.map(friend =>
|
|
||||||
getSuggestedFollowsByActor(friend.did).then(
|
await Promise.all(
|
||||||
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())
|
setDataUpdatedAt(Date.now())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue