From 6bf2e6a715995153ffe04b3524f2b226b6c64ab0 Mon Sep 17 00:00:00 2001 From: horo <143025439+horo-fox@users.noreply.github.com> Date: Sun, 7 Apr 2024 09:07:22 +0900 Subject: [PATCH 1/2] Limit imports in flight at once --- packages/astro/src/content/runtime.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/astro/src/content/runtime.ts b/packages/astro/src/content/runtime.ts index 8fcbc919104c..0ad74de3e537 100644 --- a/packages/astro/src/content/runtime.ts +++ b/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'; @@ -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); } From 3bf60064a447561b51ae1896e3cee288ea7db487 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Mon, 8 Apr 2024 23:22:18 +0800 Subject: [PATCH 2/2] Create four-zoos-taste.md --- .changeset/four-zoos-taste.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/four-zoos-taste.md diff --git a/.changeset/four-zoos-taste.md b/.changeset/four-zoos-taste.md new file mode 100644 index 000000000000..6078bcdadb6e --- /dev/null +++ b/.changeset/four-zoos-taste.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Limits parallel imports within `getCollection()` to prevent EMFILE errors when accessing files