Skip to content

Commit

Permalink
Revert "Test adding limited concurrency"
Browse files Browse the repository at this point in the history
This reverts commit 267c8e4.
  • Loading branch information
yanthomasdev committed Nov 23, 2024
1 parent 267c8e4 commit bdbc42a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 63 deletions.
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
71 changes: 26 additions & 45 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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<StatusLocalizationEntry> => {
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);
Expand Down Expand Up @@ -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,
};
}),
),
};
}

Expand Down
17 changes: 0 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bdbc42a

Please sign in to comment.