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

Limit imports in flight for getCollection #10708

Merged
merged 2 commits into from Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/four-zoos-taste.md
@@ -0,0 +1,5 @@
---
"astro": patch
---

Limits parallel imports within `getCollection()` to prevent EMFILE errors when accessing files
6 changes: 4 additions & 2 deletions packages/astro/src/content/runtime.ts
@@ -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';
Expand Down Expand Up @@ -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'
? {
Expand All @@ -103,7 +105,7 @@ export function createGetCollection({
collection: entry.collection,
data: entry.data,
};
})
}))
);
cacheEntriesByCollection.set(collection, entries);
}
Expand Down