0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-24 23:21:57 -05:00

Limit imports in flight for getCollection (#10708)

This commit is contained in:
horo 2024-04-11 23:40:14 +09:00 committed by GitHub
parent 789ce230e9
commit 742866c566
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
"astro": patch
---
Limits parallel imports within `getCollection()` to prevent EMFILE errors when accessing files

View file

@ -1,4 +1,5 @@
import type { MarkdownHeading } from '@astrojs/markdown-remark';
import pLimit from 'p-limit';
import { ZodIssueCode, string as zodString } from 'zod';
import { AstroError, AstroErrorData } from '../core/errors/index.js';
import { prependForwardSlash } from '../core/path.js';
@ -80,8 +81,9 @@ export function createGetCollection({
// Always return a new instance so consumers can safely mutate it
entries = [...cacheEntriesByCollection.get(collection)!];
} else {
const limit = pLimit(10);
entries = await Promise.all(
lazyImports.map(async (lazyImport) => {
lazyImports.map((lazyImport) => limit(async () => {
const entry = await lazyImport();
return type === 'content'
? {
@ -103,7 +105,7 @@ export function createGetCollection({
collection: entry.collection,
data: entry.data,
};
})
}))
);
cacheEntriesByCollection.set(collection, entries);
}