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
+19 -7
View File
@@ -121,17 +121,30 @@ export class SuggestedActorsViewModel {
}) })
private async fetchHardcodedSuggestions() { private async fetchHardcodedSuggestions() {
if (!this.hardCodedSuggestions) { if (this.hardCodedSuggestions) {
return
}
try { try {
const suggestionsList = getSuggestionList({ // clone the array so we can mutate it
const actors = [
...getSuggestionList({
serviceUrl: this.rootStore.session.currentSession?.service || '', 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({ const res = await this.rootStore.api.app.bsky.actor.getProfiles({
actors: suggestionsList, actors: actors.splice(0, 25),
}) })
profiles = profiles.concat(res.data.profiles)
} while (actors.length)
runInAction(() => { runInAction(() => {
this.hardCodedSuggestions = res.data.profiles.filter( this.hardCodedSuggestions = profiles.filter(
profile => !profile.myState?.follow, profile =>
!profile.myState?.follow && profile.did !== this.rootStore.me.did,
) )
}) })
} catch (e) { } catch (e) {
@@ -144,7 +157,6 @@ export class SuggestedActorsViewModel {
}) })
} }
} }
}
// state transitions // state transitions
// = // =