From c1db168a068bb851c167b1c03792a2c64a5b3914 Mon Sep 17 00:00:00 2001 From: syui Date: Mon, 2 Mar 2026 22:52:39 +0900 Subject: [PATCH] test speed promise all --- src/web/lib/api.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/web/lib/api.ts b/src/web/lib/api.ts index 48edce2..5419b55 100644 --- a/src/web/lib/api.ts +++ b/src/web/lib/api.ts @@ -148,11 +148,14 @@ async function getLocalPosts(did: string, collection: string): Promise { const indexRes = await fetch(`/at/${did}/${collection}/index.json`) if (indexRes.ok && isJsonResponse(indexRes)) { const rkeys: string[] = await indexRes.json() - const posts: Post[] = [] - for (const rkey of rkeys) { - const res = await fetch(`/at/${did}/${collection}/${rkey}.json`) - if (res.ok && isJsonResponse(res)) posts.push(await res.json()) - } + const results = await Promise.all( + rkeys.map(async (rkey) => { + const res = await fetch(`/at/${did}/${collection}/${rkey}.json`) + if (res.ok && isJsonResponse(res)) return res.json() as Promise + return null + }) + ) + const posts = results.filter((p): p is Post => p !== null) return posts.sort((a, b) => new Date(b.value.publishedAt).getTime() - new Date(a.value.publishedAt).getTime() )