Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: split getContent to chunks in getIndexedContentsList (#2354) #2549

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 (const chunk of keyChunks) {
comanche2 marked this conversation as resolved.
Show resolved Hide resolved
const result = await Promise.all(chunk.map(key => getContent(event, key)))
contents.push(...result)
}

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