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
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
6 changes: 4 additions & 2 deletions packages/astro/src/content/runtime.ts
Original file line number Diff line number Diff line change
@@ -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