0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-20 22:12:38 -05:00

Make vite-plugin-content-virtual-mod run getEntrySlug 10 at a time (#7125)

This commit is contained in:
Bjorn Lu 2023-05-23 21:54:59 +08:00 committed by GitHub
parent 2ca94269ed
commit 4ce8bf7c62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 49 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Make vite-plugin-content-virtual-mod run `getEntrySlug` 10 at a time to prevent `EMFILE: too many open files` error

View file

@ -148,6 +148,7 @@
"magic-string": "^0.27.0", "magic-string": "^0.27.0",
"mime": "^3.0.0", "mime": "^3.0.0",
"ora": "^6.1.0", "ora": "^6.1.0",
"p-limit": "^4.0.0",
"path-to-regexp": "^6.2.1", "path-to-regexp": "^6.2.1",
"preferred-pm": "^3.0.3", "preferred-pm": "^3.0.3",
"prompts": "^2.4.2", "prompts": "^2.4.2",

View file

@ -1,4 +1,5 @@
import glob from 'fast-glob'; import glob from 'fast-glob';
import pLimit from 'p-limit';
import fsMod from 'node:fs'; import fsMod from 'node:fs';
import { extname } from 'node:path'; import { extname } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url'; import { fileURLToPath, pathToFileURL } from 'node:url';
@ -114,8 +115,14 @@ export async function getStringifiedLookupMap({
} }
); );
await Promise.all( // Run 10 at a time to prevent `await getEntrySlug` from accessing the filesystem all at once.
contentGlob.map(async (filePath) => { // Each await shouldn't take too long for the work to be noticably slow too.
const limit = pLimit(10);
const promises: Promise<void>[] = [];
for (const filePath of contentGlob) {
promises.push(
limit(async () => {
const entryType = getEntryType(filePath, contentPaths, contentEntryExts, dataEntryExts); const entryType = getEntryType(filePath, contentPaths, contentEntryExts, dataEntryExts);
// Globbed ignored or unsupported entry. // Globbed ignored or unsupported entry.
// Logs warning during type generation, should ignore in lookup map. // Logs warning during type generation, should ignore in lookup map.
@ -167,6 +174,9 @@ export async function getStringifiedLookupMap({
} }
}) })
); );
}
await Promise.all(promises);
return JSON.stringify(lookupMap); return JSON.stringify(lookupMap);
} }

3
pnpm-lock.yaml generated
View file

@ -639,6 +639,9 @@ importers:
ora: ora:
specifier: ^6.1.0 specifier: ^6.1.0
version: 6.1.0 version: 6.1.0
p-limit:
specifier: ^4.0.0
version: 4.0.0
path-to-regexp: path-to-regexp:
specifier: ^6.2.1 specifier: ^6.2.1
version: 6.2.1 version: 6.2.1