From bdbc42af375eb9ad34447d1a566d62529e036e10 Mon Sep 17 00:00:00 2001 From: Yan <61414485+yanthomasdev@users.noreply.github.com> Date: Sat, 23 Nov 2024 16:49:18 -0300 Subject: [PATCH] Revert "Test adding limited concurrency" This reverts commit 267c8e4a60f97ede0c2064c49a620f5951212a97. --- packages/core/package.json | 1 - packages/core/src/index.ts | 71 ++++++++++++++------------------------ pnpm-lock.yaml | 17 --------- 3 files changed, 26 insertions(+), 63 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index 9f5cc60..34c574f 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -49,7 +49,6 @@ "jiti": "2.3.3", "js-yaml": "^4.1.0", "neotraverse": "^0.6.18", - "p-all": "^5.0.0", "path-to-regexp": "6.3.0", "picomatch": "^4.0.2", "simple-git": "^3.26.0", diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 0085d10..8a06632 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -19,7 +19,6 @@ import { externalSafePath, md5, } from './utils/utils.js'; -import pAll from 'p-all'; export type { LunariaIntegration } from './integrations/types.js'; export type * from './files/types.js'; @@ -92,27 +91,17 @@ class Lunaria { ); } - const entries: LunariaStatus = new Array(sourceFilePaths.length); - - await pAll( - sourceFilePaths.map((path) => { - return async () => { - const entry = await this.getFileStatus(path); - if (entry) entries.push(entry); - }; - }), - { - concurrency: 5, - }, - ); - - // We sort the entries by source path to make the resulting status consistent. - // That is, entries will be laid out by precedence in the `files` array, and then - // sorted internally. - const sortedEntries = entries.sort((a, b) => a.source.path.localeCompare(b.source.path)); - - for (const entry of sortedEntries) { - status.push(entry); + /** We use `Promise.all` to allow the promises to run in parallel, increasing the performance considerably. */ + const entries = ( + await Promise.all( + sourceFilePaths.map(async (path) => { + return await this.#getFileStatus(path, false); + }), + ) + ).sort((a, b) => (a?.source.path ?? '').localeCompare(b?.source.path ?? '')); + + for (const entry of entries) { + if (entry) status.push(entry); } } @@ -181,19 +170,23 @@ class Lunaria { await cache.write(this.#git.cache); } - const localizations: StatusLocalizationEntry[] = new Array(this.config.locales.length); - - const tasks = this.config.locales.map(({ lang }) => { - return async () => { - { + return { + ...file, + source: { + lang: this.config.sourceLocale.lang, + path: sourcePath, + git: latestSourceChanges, + }, + localizations: await Promise.all( + this.config.locales.map(async ({ lang }): Promise => { const localizedPath = toPath(sourcePath, lang); if (!(await exists(resolve(externalSafePath(external, this.#cwd, localizedPath))))) { - localizations.push({ + return { lang: lang, path: localizedPath, status: 'missing', - }); + }; } const latestLocaleChanges = await this.#git.getFileLatestChanges(localizedPath); @@ -228,27 +221,15 @@ class Lunaria { return {}; }; - localizations.push({ + return { lang: lang, path: localizedPath, git: latestLocaleChanges, status: isOutdated ? 'outdated' : 'up-to-date', ...(await entryTypeData()), - }); - } - }; - }); - - await pAll(tasks, { concurrency: 5 }); - - return { - ...file, - source: { - lang: this.config.sourceLocale.lang, - path: sourcePath, - git: latestSourceChanges, - }, - localizations, + }; + }), + ), }; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b0efded..ee42e69 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -92,9 +92,6 @@ importers: neotraverse: specifier: ^0.6.18 version: 0.6.18 - p-all: - specifier: ^5.0.0 - version: 5.0.0 path-to-regexp: specifier: 6.3.0 version: 6.3.0 @@ -2631,10 +2628,6 @@ packages: outdent@0.5.0: resolution: {integrity: sha512-/jHxFIzoMXdqPzTaCpFzAAWhpkSjZPF4Vsn6jAfNpmbH/ymsmd7Qc6VE9BGn0L6YMj6uwpQLxCECpus4ukKS9Q==} - p-all@5.0.0: - resolution: {integrity: sha512-pofqu/1FhCVa+78xNAptCGc9V45exFz2pvBRyIvgXkNM0Rh18Py7j8pQuSjA+zpabI46v9hRjNWmL9EAFcEbpw==} - engines: {node: '>=16'} - p-filter@2.1.0: resolution: {integrity: sha512-ZBxxZ5sL2HghephhpGAQdoskxplTwr7ICaehZwLIlfL6acuVgZPm8yBNuRAFBGEqtD/hmUeq9eqLg2ys9Xr/yw==} engines: {node: '>=8'} @@ -2663,10 +2656,6 @@ packages: resolution: {integrity: sha512-y3b8Kpd8OAN444hxfBbFfj1FY/RjtTd8tzYwhUqNYXx0fXx2iX4maP4Qr6qhIKbQXI02wTLAda4fYUbDagTUFw==} engines: {node: '>=6'} - p-map@6.0.0: - resolution: {integrity: sha512-T8BatKGY+k5rU+Q/GTYgrEf2r4xRMevAN5mtXc2aPc4rS1j3s+vWTaO2Wag94neXuCAUAs8cxBL9EeB5EA6diw==} - engines: {node: '>=16'} - p-queue@8.0.1: resolution: {integrity: sha512-NXzu9aQJTAzbBqOt2hwsR63ea7yvxJc0PwN/zobNAudYfb1B7R08SzB4TsLeSbUCuG467NhnoT0oO6w1qRO+BA==} engines: {node: '>=18'} @@ -6893,10 +6882,6 @@ snapshots: outdent@0.5.0: {} - p-all@5.0.0: - dependencies: - p-map: 6.0.0 - p-filter@2.1.0: dependencies: p-map: 2.1.0 @@ -6923,8 +6908,6 @@ snapshots: p-map@2.1.0: {} - p-map@6.0.0: {} - p-queue@8.0.1: dependencies: eventemitter3: 5.0.1