enhance(server): delete outdated notifications regularly to improve db performance
This commit is contained in:
parent
689411c19a
commit
1fd9ba8dcb
2 changed files with 10 additions and 2 deletions
|
@ -1,12 +1,12 @@
|
|||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { In, LessThan, MoreThan } from 'typeorm';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import type { UserIpsRepository } from '@/models/index.js';
|
||||
import type { NotificationsRepository, UserIpsRepository } from '@/models/index.js';
|
||||
import type { Config } from '@/config.js';
|
||||
import type Logger from '@/logger.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { QueueLoggerService } from '../QueueLoggerService.js';
|
||||
import type Bull from 'bull';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class CleanProcessorService {
|
||||
|
@ -19,6 +19,9 @@ export class CleanProcessorService {
|
|||
@Inject(DI.userIpsRepository)
|
||||
private userIpsRepository: UserIpsRepository,
|
||||
|
||||
@Inject(DI.notificationsRepository)
|
||||
private notificationsRepository: NotificationsRepository,
|
||||
|
||||
private queueLoggerService: QueueLoggerService,
|
||||
) {
|
||||
this.logger = this.queueLoggerService.logger.createSubLogger('clean');
|
||||
|
@ -32,6 +35,10 @@ export class CleanProcessorService {
|
|||
createdAt: LessThan(new Date(Date.now() - (1000 * 60 * 60 * 24 * 90))),
|
||||
});
|
||||
|
||||
this.notificationsRepository.delete({
|
||||
createdAt: LessThan(new Date(Date.now() - (1000 * 60 * 60 * 24 * 90))),
|
||||
});
|
||||
|
||||
this.logger.succ('Cleaned.');
|
||||
done();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue