mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 16:38:19 +01:00
feat: Better indexing CLI
This commit is contained in:
parent
04ff66ad8b
commit
e3f5b494cd
21
cli.ts
21
cli.ts
|
|
@ -4,6 +4,7 @@ import { client } from "~database/datasource";
|
||||||
import { createNewLocalUser } from "~database/entities/User";
|
import { createNewLocalUser } from "~database/entities/User";
|
||||||
import Table from "cli-table";
|
import Table from "cli-table";
|
||||||
import { rebuildSearchIndexes, MeiliIndexType } from "@meilisearch";
|
import { rebuildSearchIndexes, MeiliIndexType } from "@meilisearch";
|
||||||
|
import { getConfig } from "@config";
|
||||||
|
|
||||||
const args = process.argv;
|
const args = process.argv;
|
||||||
|
|
||||||
|
|
@ -110,6 +111,8 @@ if (args.length < 3) {
|
||||||
|
|
||||||
const command = args[2];
|
const command = args[2];
|
||||||
|
|
||||||
|
const config = getConfig();
|
||||||
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case "help":
|
case "help":
|
||||||
console.log(help);
|
console.log(help);
|
||||||
|
|
@ -521,6 +524,12 @@ switch (command) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "index": {
|
case "index": {
|
||||||
|
if (!config.meilisearch.enabled) {
|
||||||
|
console.log(
|
||||||
|
`${chalk.red(`✗`)} Meilisearch is not enabled in the config`
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
switch (args[3]) {
|
switch (args[3]) {
|
||||||
case "rebuild": {
|
case "rebuild": {
|
||||||
const statuses = args.includes("--statuses");
|
const statuses = args.includes("--statuses");
|
||||||
|
|
@ -541,6 +550,8 @@ switch (command) {
|
||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const timeBefore = performance.now();
|
||||||
|
|
||||||
await rebuildSearchIndexes(
|
await rebuildSearchIndexes(
|
||||||
[MeiliIndexType.Statuses],
|
[MeiliIndexType.Statuses],
|
||||||
batchSize
|
batchSize
|
||||||
|
|
@ -548,7 +559,9 @@ switch (command) {
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`${chalk.green(`✓`)} ${chalk.bold(
|
`${chalk.green(`✓`)} ${chalk.bold(
|
||||||
`Meilisearch index for statuses rebuilt`
|
`Meilisearch index for statuses rebuilt in ${chalk.bgGreen(
|
||||||
|
(performance.now() - timeBefore).toFixed(2)
|
||||||
|
)}ms`
|
||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -560,6 +573,8 @@ switch (command) {
|
||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const timeBefore = performance.now();
|
||||||
|
|
||||||
await rebuildSearchIndexes(
|
await rebuildSearchIndexes(
|
||||||
[MeiliIndexType.Accounts],
|
[MeiliIndexType.Accounts],
|
||||||
batchSize
|
batchSize
|
||||||
|
|
@ -567,7 +582,9 @@ switch (command) {
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`${chalk.green(`✓`)} ${chalk.bold(
|
`${chalk.green(`✓`)} ${chalk.bold(
|
||||||
`Meilisearch index for users rebuilt`
|
`Meilisearch index for users rebuilt in ${chalk.bgGreen(
|
||||||
|
(performance.now() - timeBefore).toFixed(2)
|
||||||
|
)}ms`
|
||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue