Skip to content

Commit

Permalink
fix: split getContent to chunks in getIndexedContentsList (#2354) (
Browse files Browse the repository at this point in the history
  • Loading branch information
comanche2 authored Feb 20, 2024
1 parent 7966323 commit a0ab377
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/runtime/server/content-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { H3Event } from 'h3'
import type { ParsedContent } from '../types'
import type { ContentQueryBuilder } from '../types/query'
import { isPreview } from './preview'
import { cacheStorage, getContent, getContentsList } from './storage'
import { cacheStorage, chunksFromArray, getContent, getContentsList } from './storage'
import { useRuntimeConfig } from '#imports'

export async function getContentIndex (event: H3Event) {
Expand Down Expand Up @@ -39,7 +39,13 @@ export async function getIndexedContentsList<T = ParsedContent> (event: H3Event,
.filter(key => (path as any).test ? (path as any).test(key) : key === String(path))
.flatMap(key => index[key])

const contents = await Promise.all(keys.map(key => getContent(event, key)))
const keyChunks = [...chunksFromArray(keys, 10)]

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

return contents as unknown as Promise<T[]>
}
Expand Down

0 comments on commit a0ab377

Please # to comment.