From 7ff1faa0f37710928b6ea9ae336c5d0397d2df94 Mon Sep 17 00:00:00 2001 From: Eric Doughty-Papassideris Date: Tue, 26 Mar 2024 12:06:22 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Accept=20array=20of=20repositories?= =?UTF-8?q?=20to=20process=20in=20order=20of=20arguments=20(#438)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/cli/cmds/search_cmds/index_all.ts | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/tdrive/backend/node/src/cli/cmds/search_cmds/index_all.ts b/tdrive/backend/node/src/cli/cmds/search_cmds/index_all.ts index d7b4e432..1af66439 100644 --- a/tdrive/backend/node/src/cli/cmds/search_cmds/index_all.ts +++ b/tdrive/backend/node/src/cli/cmds/search_cmds/index_all.ts @@ -112,15 +112,16 @@ class SearchIndexAll { if (options.repairEntities) await this.repairEntities(options, repository); - options.spinner.start("Start indexing..."); + options.spinner.start(`Start indexing ${options.repositoryName}...`); let count = 0; await iterateOverRepoPages(repository, async entities => { await this.search.upsert(entities); count += entities.length; - options.spinner.start("Indexed " + count + " items..."); + options.spinner.start(`Indexed ${count} ${options.repositoryName}...`); }); - if (count === 0) options.spinner.warn("Index finieshed; but 0 items included"); - else options.spinner.succeed(`${count} items indexed`); + if (count === 0) + options.spinner.warn(`Index ${options.repositoryName} finished; but 0 items included`); + else options.spinner.succeed(`${count} ${options.repositoryName} indexed`); const giveFlushAChanceDurationMS = 10000; options.spinner.start(`Emptying flush (${giveFlushAChanceDurationMS / 1000}s)...`); await waitTimeoutMS(giveFlushAChanceDurationMS); @@ -144,24 +145,29 @@ const command: yargs.CommandModule = { }, }, handler: async argv => { - const repositoryName = (argv[repositoryArgumentName] || "") as string; - if (!(repositoryName && SearchIndexAll.isRepoSupported(repositoryName))) - throw new Error( - `${ - repositoryName ? `Invalid (${JSON.stringify(repositoryName)})` : "Missing" - } repository.\n` + - `\tSet with --${repositoryArgumentName} .\n` + - `\tPossible values: ${SearchIndexAll.getSupportedRepoNames().join(", ")}.`, - ); + const repositoryArg = argv[repositoryArgumentName]; + const repositories = + typeof repositoryArg === "string" ? [repositoryArg] : (repositoryArg as [string]); + + function* eachOnlyOnce(list: Iterable): Iterable { + const seen = new Set(); + for (const item of list) { + if (seen.has(item)) continue; + seen.add(item); + yield item; + } + } runWithPlatform("Re-index " + argv.repository, async ({ spinner, platform }) => { try { const migrator = new SearchIndexAll(platform); - await migrator.run({ - repositoryName, - spinner, - repairEntities: !!argv.repairEntities, - }); + for (const repositoryName of eachOnlyOnce(repositories)) { + await migrator.run({ + repositoryName, + spinner, + repairEntities: !!argv.repairEntities, + }); + } } catch (err) { spinner.fail(`Error indexing: ${err.stack}`); return 1;