mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-25 16:33:08 +02:00
6277a5545c
* wip * wip * wip * wip * wip * wip * Update NoteCreateService.ts * wip * wip * wip * wip * Update NoteCreateService.ts * wip * Update NoteCreateService.ts * wip * Update user-notes.ts * wip * wip * wip * Update NoteCreateService.ts * wip * Update timeline.ts * Update timeline.ts * Update timeline.ts * Update timeline.ts * Update timeline.ts * wip * Update timelines.ts * Update timelines.ts * Update timelines.ts * wip * wip * wip * Update timelines.ts * Update misskey-js.api.md * Update timelines.ts * Update timelines.ts * wip * wip * wip * Update timelines.ts * wip * Update timelines.ts * wip * test * Update activitypub.ts * refactor: UserListJoining -> UserListMembership * Update NoteCreateService.ts * wip
70 lines
2 KiB
TypeScript
70 lines
2 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
import { In, LessThan } from 'typeorm';
|
|
import { DI } from '@/di-symbols.js';
|
|
import type { AntennasRepository, RoleAssignmentsRepository, UserIpsRepository } from '@/models/_.js';
|
|
import type Logger from '@/logger.js';
|
|
import { bindThis } from '@/decorators.js';
|
|
import { IdService } from '@/core/IdService.js';
|
|
import type { Config } from '@/config.js';
|
|
import { QueueLoggerService } from '../QueueLoggerService.js';
|
|
import type * as Bull from 'bullmq';
|
|
|
|
@Injectable()
|
|
export class CleanProcessorService {
|
|
private logger: Logger;
|
|
|
|
constructor(
|
|
@Inject(DI.config)
|
|
private config: Config,
|
|
|
|
@Inject(DI.userIpsRepository)
|
|
private userIpsRepository: UserIpsRepository,
|
|
|
|
@Inject(DI.antennasRepository)
|
|
private antennasRepository: AntennasRepository,
|
|
|
|
@Inject(DI.roleAssignmentsRepository)
|
|
private roleAssignmentsRepository: RoleAssignmentsRepository,
|
|
|
|
private queueLoggerService: QueueLoggerService,
|
|
private idService: IdService,
|
|
) {
|
|
this.logger = this.queueLoggerService.logger.createSubLogger('clean');
|
|
}
|
|
|
|
@bindThis
|
|
public async process(): Promise<void> {
|
|
this.logger.info('Cleaning...');
|
|
|
|
this.userIpsRepository.delete({
|
|
createdAt: LessThan(new Date(Date.now() - (1000 * 60 * 60 * 24 * 90))),
|
|
});
|
|
|
|
// 使われてないアンテナを停止
|
|
if (this.config.deactivateAntennaThreshold > 0) {
|
|
this.antennasRepository.update({
|
|
lastUsedAt: LessThan(new Date(Date.now() - this.config.deactivateAntennaThreshold)),
|
|
}, {
|
|
isActive: false,
|
|
});
|
|
}
|
|
|
|
const expiredRoleAssignments = await this.roleAssignmentsRepository.createQueryBuilder('assign')
|
|
.where('assign.expiresAt IS NOT NULL')
|
|
.andWhere('assign.expiresAt < :now', { now: new Date() })
|
|
.getMany();
|
|
|
|
if (expiredRoleAssignments.length > 0) {
|
|
await this.roleAssignmentsRepository.delete({
|
|
id: In(expiredRoleAssignments.map(x => x.id)),
|
|
});
|
|
}
|
|
|
|
this.logger.succ('Cleaned.');
|
|
}
|
|
}
|