Skip to content

Commit

Permalink
Limit imports in flight at once
Browse files Browse the repository at this point in the history
  • Loading branch information
horo-fox authored Apr 7, 2024
1 parent ecb4435 commit 6bf2e6a
Showing 1 changed file with 4 additions and 2 deletions.
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

0 comments on commit 6bf2e6a

Please sign in to comment.