✨ Accept array of repositories to process in order of arguments (#438)
This commit is contained in:
committed by
ericlinagora
parent
8a46780d3f
commit
7ff1faa0f3
@@ -112,15 +112,16 @@ class SearchIndexAll {
|
|||||||
|
|
||||||
if (options.repairEntities) await this.repairEntities(options, repository);
|
if (options.repairEntities) await this.repairEntities(options, repository);
|
||||||
|
|
||||||
options.spinner.start("Start indexing...");
|
options.spinner.start(`Start indexing ${options.repositoryName}...`);
|
||||||
let count = 0;
|
let count = 0;
|
||||||
await iterateOverRepoPages(repository, async entities => {
|
await iterateOverRepoPages(repository, async entities => {
|
||||||
await this.search.upsert(entities);
|
await this.search.upsert(entities);
|
||||||
count += entities.length;
|
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");
|
if (count === 0)
|
||||||
else options.spinner.succeed(`${count} items indexed`);
|
options.spinner.warn(`Index ${options.repositoryName} finished; but 0 items included`);
|
||||||
|
else options.spinner.succeed(`${count} ${options.repositoryName} indexed`);
|
||||||
const giveFlushAChanceDurationMS = 10000;
|
const giveFlushAChanceDurationMS = 10000;
|
||||||
options.spinner.start(`Emptying flush (${giveFlushAChanceDurationMS / 1000}s)...`);
|
options.spinner.start(`Emptying flush (${giveFlushAChanceDurationMS / 1000}s)...`);
|
||||||
await waitTimeoutMS(giveFlushAChanceDurationMS);
|
await waitTimeoutMS(giveFlushAChanceDurationMS);
|
||||||
@@ -144,24 +145,29 @@ const command: yargs.CommandModule<unknown, unknown> = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
handler: async argv => {
|
handler: async argv => {
|
||||||
const repositoryName = (argv[repositoryArgumentName] || "") as string;
|
const repositoryArg = argv[repositoryArgumentName];
|
||||||
if (!(repositoryName && SearchIndexAll.isRepoSupported(repositoryName)))
|
const repositories =
|
||||||
throw new Error(
|
typeof repositoryArg === "string" ? [repositoryArg] : (repositoryArg as [string]);
|
||||||
`${
|
|
||||||
repositoryName ? `Invalid (${JSON.stringify(repositoryName)})` : "Missing"
|
function* eachOnlyOnce<T>(list: Iterable<T>): Iterable<T> {
|
||||||
} repository.\n` +
|
const seen = new Set<T>();
|
||||||
`\tSet with --${repositoryArgumentName} .\n` +
|
for (const item of list) {
|
||||||
`\tPossible values: ${SearchIndexAll.getSupportedRepoNames().join(", ")}.`,
|
if (seen.has(item)) continue;
|
||||||
);
|
seen.add(item);
|
||||||
|
yield item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
runWithPlatform("Re-index " + argv.repository, async ({ spinner, platform }) => {
|
runWithPlatform("Re-index " + argv.repository, async ({ spinner, platform }) => {
|
||||||
try {
|
try {
|
||||||
const migrator = new SearchIndexAll(platform);
|
const migrator = new SearchIndexAll(platform);
|
||||||
await migrator.run({
|
for (const repositoryName of eachOnlyOnce(repositories)) {
|
||||||
repositoryName,
|
await migrator.run({
|
||||||
spinner,
|
repositoryName,
|
||||||
repairEntities: !!argv.repairEntities,
|
spinner,
|
||||||
});
|
repairEntities: !!argv.repairEntities,
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
spinner.fail(`Error indexing: ${err.stack}`);
|
spinner.fail(`Error indexing: ${err.stack}`);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user