Skip to content

Commit

Permalink
fix: fetch content chunked (#2321)
Browse files Browse the repository at this point in the history
  • Loading branch information
manniL committed Sep 18, 2023
1 parent 6eeb719 commit 84874c5
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/runtime/server/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,22 @@ export const getContentsIds = async (event: H3Event, prefix?: string) => {
return keys.filter(contentIgnorePredicate)
}

export function* chunksFromArray<T> (arr: T[], n: number) : Generator<T[], void> {
for (let i = 0; i < arr.length; i += n) {
yield arr.slice(i, i + n)
}
}

export const getContentsList = async (event: H3Event, prefix?: string) => {
const keys = await getContentsIds(event, prefix)
const contents = await Promise.all(keys.map(key => getContent(event, key)))

const keyChunks = [...chunksFromArray(keys, 10)]

const contents: ParsedContent[] = []
for (const chunk of keyChunks) {
const result = await Promise.all(chunk.map(key => getContent(event, key)))
contents.push(...result)
}

return contents
}
Expand Down

0 comments on commit 84874c5

Please sign in to comment.