From 0c1a2cec69a05b04f8191f5b73f33fce744e78dc Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Sun, 15 Mar 2026 14:52:23 +0100 Subject: [PATCH] feat: --batch for hosting prune Signed-off-by: David Dal Busco --- src/help/hosting.prune.help.ts | 1 + src/services/assets/_args.services.ts | 22 ++++++++++++++++++++++ src/services/assets/deploy.services.ts | 26 +++----------------------- src/services/assets/prune.services.ts | 6 +++++- 4 files changed, 31 insertions(+), 24 deletions(-) create mode 100644 src/services/assets/_args.services.ts diff --git a/src/help/hosting.prune.help.ts b/src/help/hosting.prune.help.ts index 2dc0860b..e06b2d25 100644 --- a/src/help/hosting.prune.help.ts +++ b/src/help/hosting.prune.help.ts @@ -6,6 +6,7 @@ import {TITLE} from './help'; const usage = `Usage: ${green('juno')} ${cyan('hosting')} ${magenta('prune')} ${yellow('[options]')} Options: + ${yellow('--batch')} Number of files to prune in parallel per batch (default: 100). ${yellow('--dry-run')} List stale files that would be deleted without actually deleting them. ${OPTIONS_ENV} ${OPTION_HELP}`; diff --git a/src/services/assets/_args.services.ts b/src/services/assets/_args.services.ts new file mode 100644 index 00000000..ee842250 --- /dev/null +++ b/src/services/assets/_args.services.ts @@ -0,0 +1,22 @@ +import {isEmptyString} from '@dfinity/utils'; +import {nextArg} from '@junobuild/cli-tools'; + +export const parseBatchSize = (args?: string[]): {valid: boolean; value?: number} => { + const batchArg = nextArg({args, option: '--batch'}); + + if (isEmptyString(batchArg)) { + return {valid: true}; + } + + const batch = parseInt(batchArg); + + if (isNaN(batch)) { + return {valid: false}; + } + + if (batch <= 0) { + return {valid: false}; + } + + return {valid: true, value: batch}; +}; diff --git a/src/services/assets/deploy.services.ts b/src/services/assets/deploy.services.ts index 24e28636..12104e6d 100644 --- a/src/services/assets/deploy.services.ts +++ b/src/services/assets/deploy.services.ts @@ -1,5 +1,4 @@ -import {isEmptyString} from '@dfinity/utils'; -import {hasArgs, nextArg} from '@junobuild/cli-tools'; +import {hasArgs} from '@junobuild/cli-tools'; import {yellow} from 'kleur'; import {compare} from 'semver'; import {noJunoConfig} from '../../configs/juno.config'; @@ -9,6 +8,7 @@ import {applyConfig} from '../config/apply.services'; import {init} from '../config/init.services'; import {links} from '../links.services'; import {getSatelliteVersion} from '../version.services'; +import {parseBatchSize} from './_args.services'; import {deployImmediate} from './_deploy/deploy.individual.services'; import {deployWithProposal as executeDeployWithProposal} from './_deploy/deploy.with-proposal.services'; @@ -42,7 +42,7 @@ const executeDeploy = async (args?: string[]) => { // wouldn't harm usage, it might prevent crawlers from properly fetching content. const deprecatedGzip = compare(result.version, '0.1.1') < 0 ? '**/*.+(css|js|mjs)' : undefined; - const {value: uploadBatchSize} = parseUploadBatchSize(args); + const {value: uploadBatchSize} = parseBatchSize(args); const clearOption = hasArgs({args, options: ['--clear']}); const immediate = hasArgs({args, options: ['-i', '--immediate']}); @@ -96,23 +96,3 @@ const deployWithProposal = async ({ proposalId }); }; - -const parseUploadBatchSize = (args?: string[]): {valid: boolean; value?: number} => { - const batchArg = nextArg({args, option: '--batch'}); - - if (isEmptyString(batchArg)) { - return {valid: true}; - } - - const batch = parseInt(batchArg); - - if (isNaN(batch)) { - return {valid: false}; - } - - if (batch <= 0) { - return {valid: false}; - } - - return {valid: true, value: batch}; -}; diff --git a/src/services/assets/prune.services.ts b/src/services/assets/prune.services.ts index 6b75e0c8..fb428795 100644 --- a/src/services/assets/prune.services.ts +++ b/src/services/assets/prune.services.ts @@ -12,6 +12,7 @@ import {noJunoConfig} from '../../configs/juno.config'; import type {SatelliteParametersWithId} from '../../types/satellite'; import {assertConfigAndLoadSatelliteContext} from '../../utils/juno.config.utils'; import {consoleNoConfigFound} from '../../utils/msg.utils'; +import {parseBatchSize} from './_args.services'; import {listAssets} from './_assets.list.services'; export const prune = async (args?: string[]) => { @@ -26,6 +27,8 @@ export const prune = async (args?: string[]) => { const executePrune = async (args?: string[]) => { const dryRun = hasArgs({args, options: ['--dry-run']}); + const {value: pruneBatchSize} = parseBatchSize(args); + const {satellite, satelliteConfig} = await assertConfigAndLoadSatelliteContext(); const listExistingAssets = async ({startAfter}: {startAfter?: string}): Promise => @@ -43,7 +46,8 @@ const executePrune = async (args?: string[]) => { config: satelliteConfig, listAssets: listExistingAssets, assertSourceDirExists, - dryRun + dryRun, + batchSize: pruneBatchSize }, pruneFn });