Skip to content

Commit 2919da8

Browse files
committed
Improve parallelism during iteration
1 parent 9d98d4f commit 2919da8

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

src/cli/commands/manage/publish-content.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { ensureVariantFileExists, type Variants } from '../../util/variants.js';
2323
import {
2424
loadStorageProviderFromStaticPublishRc,
2525
StorageProviderBatch,
26+
type StorageProviderBatchEntry,
2627
} from '../../storage/storage-provider.js';
2728

2829
// Storage key format:
@@ -319,7 +320,7 @@ export async function action(actionArgs: string[]) {
319320
const baseHashToVariantMetadatasMap = new Map<string, VariantMetadataMap>();
320321

321322
// #### Iterate files
322-
for (const file of files) {
323+
const filePromises = files.map(async (file) => {
323324
// #### asset key
324325
const assetKey = file.slice(publicDirRoot.length)
325326
// in Windows, assetKey will otherwise end up as \path\file.html
@@ -354,7 +355,7 @@ export async function action(actionArgs: string[]) {
354355
}
355356

356357
if (!includeAsset) {
357-
continue;
358+
return;
358359
}
359360

360361
// #### Base file size, hash, last modified time
@@ -376,6 +377,9 @@ export async function action(actionArgs: string[]) {
376377
'original',
377378
...contentCompression,
378379
] as const;
380+
381+
const batchItems: StorageProviderBatchEntry[] = [];
382+
379383
for (const variant of variants) {
380384
let variantKey = `${publishId}_files_sha256_${baseHash}`;
381385
let variantFilename = `${baseHash}`;
@@ -446,7 +450,7 @@ export async function action(actionArgs: string[]) {
446450
metadataJson.numChunks = String(variantMetadata.numChunks);
447451
}
448452

449-
batch.add({
453+
batchItems.push({
450454
write: !variantMetadata.existsInKvStore,
451455
size: variantMetadata.size,
452456
key: variantKey,
@@ -462,14 +466,29 @@ export async function action(actionArgs: string[]) {
462466
}
463467
}
464468

465-
assetsIndex[assetKey] = {
466-
key: `sha256:${baseHash}`,
467-
size: baseSize,
468-
contentType: contentTypeTestResult.contentType,
469-
lastModifiedTime,
470-
variants: variantsToKeep,
469+
return {
470+
assetKey,
471+
asset: {
472+
key: `sha256:${baseHash}`,
473+
size: baseSize,
474+
contentType: contentTypeTestResult.contentType,
475+
lastModifiedTime,
476+
variants: variantsToKeep,
477+
},
478+
batchItems,
471479
};
480+
});
472481

482+
const fileResults = await Promise.all(filePromises);
483+
484+
for (const result of fileResults) {
485+
if (result == null) {
486+
continue;
487+
}
488+
assetsIndex[result.assetKey] = result.asset;
489+
for (const batchItem of result.batchItems) {
490+
batch.add(batchItem);
491+
}
473492
}
474493
console.log(`✅ Scan complete.`)
475494

0 commit comments

Comments
 (0)