Run all update operations in parallel

This commit is contained in:
Matt Isenhower 2024-11-20 21:45:56 -08:00
parent fbdea0f3c2
commit 441c0b262f
2 changed files with 11 additions and 2 deletions

View File

@ -4,6 +4,9 @@ import mkdirp from 'mkdirp';
import jsonpath from 'jsonpath';
import get from 'lodash/get.js';
import set from 'lodash/set.js';
import pLimit from 'p-limit';
const limit = pLimit(1);
function makeArray(value) {
return Array.isArray(value) ? value : [value];
@ -55,6 +58,12 @@ export class LocalizationProcessor {
}
async updateLocalizations(data) {
// We're reading, modifying, and writing back to the same file,
// so we have to make sure the whole operation is atomic.
return limit(() => this._updateLocalizations(data));
}
async _updateLocalizations(data) {
let localizations = await this.readData();
for (let { path, value } of this.dataIterations(data)) {

View File

@ -43,7 +43,7 @@ export async function update(config = 'default') {
let settings = configs[config];
for (let updater of updaters()) {
await Promise.all(updaters().map(async updater => {
updater.settings = settings;
try {
await updater.updateIfNeeded();
@ -51,7 +51,7 @@ export async function update(config = 'default') {
console.error(e);
Sentry.captureException(e);
}
}
}));
if (canSync()) {
await ImageProcessor.onIdle();