1
0

test speed promise all

This commit is contained in:
2026-03-02 22:52:39 +09:00
parent a99262704b
commit c1db168a06

View File

@@ -148,11 +148,14 @@ async function getLocalPosts(did: string, collection: string): Promise<Post[]> {
const indexRes = await fetch(`/at/${did}/${collection}/index.json`) const indexRes = await fetch(`/at/${did}/${collection}/index.json`)
if (indexRes.ok && isJsonResponse(indexRes)) { if (indexRes.ok && isJsonResponse(indexRes)) {
const rkeys: string[] = await indexRes.json() const rkeys: string[] = await indexRes.json()
const posts: Post[] = [] const results = await Promise.all(
for (const rkey of rkeys) { rkeys.map(async (rkey) => {
const res = await fetch(`/at/${did}/${collection}/${rkey}.json`) const res = await fetch(`/at/${did}/${collection}/${rkey}.json`)
if (res.ok && isJsonResponse(res)) posts.push(await res.json()) if (res.ok && isJsonResponse(res)) return res.json() as Promise<Post>
} return null
})
)
const posts = results.filter((p): p is Post => p !== null)
return posts.sort((a, b) => return posts.sort((a, b) =>
new Date(b.value.publishedAt).getTime() - new Date(a.value.publishedAt).getTime() new Date(b.value.publishedAt).getTime() - new Date(a.value.publishedAt).getTime()
) )