Skip to content

Commit

Permalink
fix: split getContent to chunks in getIndexedContentsList (nuxt#2354
Browse files Browse the repository at this point in the history
)
  • Loading branch information
comanche2 committed Feb 19, 2024
1 parent d3b2d76 commit a616912
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/runtime/server/content-index.ts
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 (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 a616912

Please sign in to comment.