mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: apply feedback updates
This commit is contained in:
parent
e134ba65e9
commit
cf350c1048
@ -11,7 +11,7 @@ import path from 'path';
|
||||
import { CacheModule } from '@nestjs/cache-manager';
|
||||
// eslint-disable-next-line import/order
|
||||
import { MailerModule } from '@nestjs-modules/mailer';
|
||||
import { Module, OnApplicationBootstrap } from '@nestjs/common';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { APP_GUARD } from '@nestjs/core';
|
||||
import { EventEmitterModule } from '@nestjs/event-emitter';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
@ -33,15 +33,13 @@ import { AppService } from './app.service';
|
||||
import { AttachmentModule } from './attachment/attachment.module';
|
||||
import { ChannelModule } from './channel/channel.module';
|
||||
import { ChatModule } from './chat/chat.module';
|
||||
import { CleanupModule } from './cleanup/cleanup.module';
|
||||
import { CleanupService } from './cleanup/cleanup.service';
|
||||
import { CmsModule } from './cms/cms.module';
|
||||
import { config } from './config';
|
||||
import { ExtensionModule } from './extention/extension.module';
|
||||
import extraModules from './extra';
|
||||
import { HelperModule } from './helper/helper.module';
|
||||
import { I18nModule } from './i18n/i18n.module';
|
||||
import { LoggerModule } from './logger/logger.module';
|
||||
import { LoggerService } from './logger/logger.service';
|
||||
import { MigrationModule } from './migration/migration.module';
|
||||
import { NlpModule } from './nlp/nlp.module';
|
||||
import { PluginsModule } from './plugins/plugins.module';
|
||||
@ -155,7 +153,7 @@ const i18nOptions: I18nOptions = {
|
||||
max: config.cache.max,
|
||||
}),
|
||||
MigrationModule,
|
||||
CleanupModule,
|
||||
ExtensionModule,
|
||||
...extraModules,
|
||||
],
|
||||
controllers: [AppController],
|
||||
@ -165,17 +163,4 @@ const i18nOptions: I18nOptions = {
|
||||
AppService,
|
||||
],
|
||||
})
|
||||
export class HexabotModule implements OnApplicationBootstrap {
|
||||
constructor(
|
||||
private readonly loggerService: LoggerService,
|
||||
private readonly cleanupService: CleanupService,
|
||||
) {}
|
||||
|
||||
async onApplicationBootstrap() {
|
||||
try {
|
||||
await this.cleanupService.deleteUnusedSettings();
|
||||
} catch (error) {
|
||||
this.loggerService.error('Unable to delete unused settings', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
export class HexabotModule {}
|
||||
|
||||
@ -96,7 +96,7 @@ describe('CleanupService', () => {
|
||||
...cleanupService.getHelperNamespaces(),
|
||||
];
|
||||
|
||||
await cleanupService.deleteUnusedSettings();
|
||||
await cleanupService.pruneExtensionSettings();
|
||||
const cleanSettings = await settingService.findAll();
|
||||
const filteredSettings = initialSettings.filter(
|
||||
({ group }) =>
|
||||
@ -25,7 +25,9 @@ export class CleanupService {
|
||||
private readonly channelService: ChannelService,
|
||||
) {}
|
||||
|
||||
private async deleteMany(criteria: TCriteria[]): Promise<DeleteResult> {
|
||||
private async deleteManyBySuffixAndNamespaces(
|
||||
criteria: TCriteria[],
|
||||
): Promise<DeleteResult> {
|
||||
return await this.settingService.deleteMany({
|
||||
$or: criteria.map(({ suffix, namespaces }) => ({
|
||||
group: { $regex: suffix, $nin: namespaces },
|
||||
@ -45,17 +47,17 @@ export class CleanupService {
|
||||
.map((helper) => helper.getNamespace<TExtractExtension<'helper'>>());
|
||||
}
|
||||
|
||||
public async deleteUnusedSettings() {
|
||||
public async pruneExtensionSettings() {
|
||||
const channels = this.getChannelNamespaces();
|
||||
const helpers = this.getHelperNamespaces();
|
||||
const { deletedCount } = await this.deleteMany([
|
||||
const { deletedCount } = await this.deleteManyBySuffixAndNamespaces([
|
||||
{ suffix: '_channel', namespaces: channels },
|
||||
{ suffix: '_helper', namespaces: helpers },
|
||||
]);
|
||||
|
||||
if (deletedCount > 0) {
|
||||
this.loggerService.log(
|
||||
`${deletedCount} unused setting${deletedCount === 1 ? '' : 's'} are successfully deleted!`,
|
||||
`${deletedCount} unused setting${deletedCount === 1 ? '' : 's'} ${deletedCount === 1 ? 'is' : 'are'} successfully deleted!`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,9 @@
|
||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||
*/
|
||||
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { Global, Module, OnApplicationBootstrap } from '@nestjs/common';
|
||||
|
||||
import { LoggerService } from '@/logger/logger.service';
|
||||
|
||||
import { CleanupService } from './cleanup.service';
|
||||
|
||||
@ -15,4 +17,17 @@ import { CleanupService } from './cleanup.service';
|
||||
providers: [CleanupService],
|
||||
exports: [CleanupService],
|
||||
})
|
||||
export class CleanupModule {}
|
||||
export class ExtensionModule implements OnApplicationBootstrap {
|
||||
constructor(
|
||||
private readonly loggerService: LoggerService,
|
||||
private readonly cleanupService: CleanupService,
|
||||
) {}
|
||||
|
||||
async onApplicationBootstrap() {
|
||||
try {
|
||||
await this.cleanupService.pruneExtensionSettings();
|
||||
} catch (error) {
|
||||
this.loggerService.error('Unable to delete unused settings', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user