Fix to suggested follows: chunk the hardcoded fetches to 25 at a time (close #196) (#198)

This commit is contained in:
Paul Frazee
2023-02-14 16:55:01 -06:00
committed by GitHub
parent 9b08fb93a0
commit ffd0b62860
2 changed files with 37 additions and 25 deletions
+7 -7
View File
@@ -1,18 +1,18 @@
const productionSuggestedFollows = [
'john',
'visakanv ',
'saz ',
'steph ',
'ratzlaff ',
'visakanv',
'saz',
'steph',
'ratzlaff',
'beth',
'weisser ',
'katherine ',
'weisser',
'katherine',
'annagat',
'josh',
'lurkshark',
'amir',
'amyxzh',
'danielle ',
'danielle',
'jack-frazee',
'vibes',
'cat',
+30 -18
View File
@@ -121,28 +121,40 @@ export class SuggestedActorsViewModel {
})
private async fetchHardcodedSuggestions() {
if (!this.hardCodedSuggestions) {
try {
const suggestionsList = getSuggestionList({
if (this.hardCodedSuggestions) {
return
}
try {
// clone the array so we can mutate it
const actors = [
...getSuggestionList({
serviceUrl: this.rootStore.session.currentSession?.service || '',
})
}),
]
// fetch the profiles in chunks of 25 (the limit allowed by `getProfiles`)
let profiles: Profile.View[] = []
do {
const res = await this.rootStore.api.app.bsky.actor.getProfiles({
actors: suggestionsList,
actors: actors.splice(0, 25),
})
runInAction(() => {
this.hardCodedSuggestions = res.data.profiles.filter(
profile => !profile.myState?.follow,
)
})
} catch (e) {
this.rootStore.log.error(
'Failed to getProfiles() for suggested follows',
{e},
profiles = profiles.concat(res.data.profiles)
} while (actors.length)
runInAction(() => {
this.hardCodedSuggestions = profiles.filter(
profile =>
!profile.myState?.follow && profile.did !== this.rootStore.me.did,
)
runInAction(() => {
this.hardCodedSuggestions = []
})
}
})
} catch (e) {
this.rootStore.log.error(
'Failed to getProfiles() for suggested follows',
{e},
)
runInAction(() => {
this.hardCodedSuggestions = []
})
}
}