Fix: dont request more than 25 posts at a time (close [APP-561]) (#534)

zio/stable
Paul Frazee 2023-04-25 20:47:37 -05:00 committed by GitHub
parent f33a355a1a
commit 9b86cb5c36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 4 deletions

View File

@ -10,6 +10,7 @@ import {
ComAtprotoLabelDefs, ComAtprotoLabelDefs,
} from '@atproto/api' } from '@atproto/api'
import AwaitLock from 'await-lock' import AwaitLock from 'await-lock'
import chunk from 'lodash.chunk'
import {bundleAsync} from 'lib/async/bundle' import {bundleAsync} from 'lib/async/bundle'
import {RootStoreModel} from '../root-store' import {RootStoreModel} from '../root-store'
import {PostThreadModel} from '../content/post-thread' import {PostThreadModel} from '../content/post-thread'
@ -554,10 +555,15 @@ export class NotificationsFeedModel {
// fetch additional data // fetch additional data
if (addedPostMap.size > 0) { if (addedPostMap.size > 0) {
const postsRes = await this.rootStore.agent.app.bsky.feed.getPosts({ const uriChunks = chunk(Array.from(addedPostMap.keys()), 25)
uris: Array.from(addedPostMap.keys()), const postsChunks = await Promise.all(
}) uriChunks.map(uris =>
for (const post of postsRes.data.posts) { this.rootStore.agent.app.bsky.feed
.getPosts({uris})
.then(res => res.data.posts),
),
)
for (const post of postsChunks.flat()) {
const models = addedPostMap.get(post.uri) const models = addedPostMap.get(post.uri)
if (models?.length) { if (models?.length) {
for (const model of models) { for (const model of models) {