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:
parent
789ce230e9
commit
742866c566
2 changed files with 9 additions and 2 deletions
5
.changeset/four-zoos-taste.md
Normal file
5
.changeset/four-zoos-taste.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
Limits parallel imports within `getCollection()` to prevent EMFILE errors when accessing files
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue