mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 00:18:19 +01:00
fix(cli): 🐛 Don't federate changes to remote users, initialize search indexer on all CLI commands
This commit is contained in:
parent
49a2552e96
commit
57b295ccf2
|
|
@ -49,19 +49,20 @@ export class SonicSearchManager {
|
||||||
/**
|
/**
|
||||||
* Connect to Sonic
|
* Connect to Sonic
|
||||||
*/
|
*/
|
||||||
async connect(): Promise<void> {
|
async connect(silent = false): Promise<void> {
|
||||||
if (!this.config.sonic.enabled) {
|
if (!this.config.sonic.enabled) {
|
||||||
this.logger.info`Sonic search is disabled`;
|
!silent && this.logger.info`Sonic search is disabled`;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.info`Connecting to Sonic...`;
|
!silent && this.logger.info`Connecting to Sonic...`;
|
||||||
|
|
||||||
// Connect to Sonic
|
// Connect to Sonic
|
||||||
await new Promise<boolean>((resolve, reject) => {
|
await new Promise<boolean>((resolve, reject) => {
|
||||||
this.searchChannel.connect({
|
this.searchChannel.connect({
|
||||||
connected: () => {
|
connected: () => {
|
||||||
this.logger.info`Connected to Sonic Search Channel`;
|
!silent &&
|
||||||
|
this.logger.info`Connected to Sonic Search Channel`;
|
||||||
resolve(true);
|
resolve(true);
|
||||||
},
|
},
|
||||||
disconnected: () =>
|
disconnected: () =>
|
||||||
|
|
@ -84,7 +85,8 @@ export class SonicSearchManager {
|
||||||
await new Promise<boolean>((resolve, reject) => {
|
await new Promise<boolean>((resolve, reject) => {
|
||||||
this.ingestChannel.connect({
|
this.ingestChannel.connect({
|
||||||
connected: () => {
|
connected: () => {
|
||||||
this.logger.info`Connected to Sonic Ingest Channel`;
|
!silent &&
|
||||||
|
this.logger.info`Connected to Sonic Ingest Channel`;
|
||||||
resolve(true);
|
resolve(true);
|
||||||
},
|
},
|
||||||
disconnected: () =>
|
disconnected: () =>
|
||||||
|
|
@ -108,7 +110,7 @@ export class SonicSearchManager {
|
||||||
this.searchChannel.ping(),
|
this.searchChannel.ping(),
|
||||||
this.ingestChannel.ping(),
|
this.ingestChannel.ping(),
|
||||||
]);
|
]);
|
||||||
this.logger.info`Connected to Sonic`;
|
!silent && this.logger.info`Connected to Sonic`;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.fatal`Error while connecting to Sonic: ${error}`;
|
this.logger.fatal`Error while connecting to Sonic: ${error}`;
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { Command } from "@oclif/core";
|
import { Command } from "@oclif/core";
|
||||||
|
import { searchManager } from "~/classes/search/search-manager";
|
||||||
import { setupDatabase } from "~/drizzle/db";
|
import { setupDatabase } from "~/drizzle/db";
|
||||||
|
|
||||||
export abstract class BaseCommand<_T extends typeof Command> extends Command {
|
export abstract class BaseCommand<_T extends typeof Command> extends Command {
|
||||||
|
|
@ -6,5 +7,6 @@ export abstract class BaseCommand<_T extends typeof Command> extends Command {
|
||||||
await super.init();
|
await super.init();
|
||||||
|
|
||||||
await setupDatabase(false);
|
await setupDatabase(false);
|
||||||
|
await searchManager.connect(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,6 @@ export default class IndexRebuild extends BaseCommand<typeof IndexRebuild> {
|
||||||
this.exit(1);
|
this.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
await searchManager.connect();
|
|
||||||
|
|
||||||
const spinner = ora("Rebuilding search indexes").start();
|
const spinner = ora("Rebuilding search indexes").start();
|
||||||
|
|
||||||
switch (args.type) {
|
switch (args.type) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import confirm from "@inquirer/confirm";
|
import confirm from "@inquirer/confirm";
|
||||||
import { Flags } from "@oclif/core";
|
import { Flags } from "@oclif/core";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
|
import ora from "ora";
|
||||||
import { UserFinderCommand } from "~/cli/classes";
|
import { UserFinderCommand } from "~/cli/classes";
|
||||||
import { formatArray } from "~/cli/utils/format";
|
import { formatArray } from "~/cli/utils/format";
|
||||||
|
|
||||||
|
|
@ -78,8 +79,11 @@ export default class UserRefetch extends UserFinderCommand<typeof UserRefetch> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const spinner = ora("Refetching users").start();
|
||||||
|
|
||||||
for (const user of users) {
|
for (const user of users) {
|
||||||
try {
|
try {
|
||||||
|
spinner.text = `Refetching user ${user.data.username}`;
|
||||||
await user.updateFromRemote();
|
await user.updateFromRemote();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.log(
|
this.log(
|
||||||
|
|
@ -93,6 +97,8 @@ export default class UserRefetch extends UserFinderCommand<typeof UserRefetch> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spinner.succeed("Refetched users");
|
||||||
|
|
||||||
this.exit(0);
|
this.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -576,18 +576,19 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
||||||
|
|
||||||
// If something important is updated, federate it
|
// If something important is updated, federate it
|
||||||
if (
|
if (
|
||||||
newUser.username ||
|
this.isLocal() &&
|
||||||
newUser.displayName ||
|
(newUser.username ||
|
||||||
newUser.note ||
|
newUser.displayName ||
|
||||||
newUser.avatar ||
|
newUser.note ||
|
||||||
newUser.header ||
|
newUser.avatar ||
|
||||||
newUser.fields ||
|
newUser.header ||
|
||||||
newUser.publicKey ||
|
newUser.fields ||
|
||||||
newUser.isAdmin ||
|
newUser.publicKey ||
|
||||||
newUser.isBot ||
|
newUser.isAdmin ||
|
||||||
newUser.isLocked ||
|
newUser.isBot ||
|
||||||
newUser.endpoints ||
|
newUser.isLocked ||
|
||||||
newUser.isDiscoverable
|
newUser.endpoints ||
|
||||||
|
newUser.isDiscoverable)
|
||||||
) {
|
) {
|
||||||
await this.federateToFollowers(this.toLysand());
|
await this.federateToFollowers(this.toLysand());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue