saving work

This commit is contained in:
jaina heartles 2024-03-12 17:12:30 -07:00
parent 88ca0c14ef
commit 87c6a36823
4 changed files with 84 additions and 0 deletions

View file

@ -69,6 +69,12 @@ export class QueueService {
repeat: { pattern: '*/5 * * * *' }, repeat: { pattern: '*/5 * * * *' },
removeOnComplete: true, removeOnComplete: true,
}); });
this.systemQueue.add('autoDeleteNotes', {
}, {
repeat: { pattern: '*/1 * * * *' },
removeOnComplete: true,
});
} }
@bindThis @bindThis

View file

@ -13,6 +13,7 @@ import { EndedPollNotificationProcessorService } from './processors/EndedPollNot
import { InboxProcessorService } from './processors/InboxProcessorService.js'; import { InboxProcessorService } from './processors/InboxProcessorService.js';
import { WebhookDeliverProcessorService } from './processors/WebhookDeliverProcessorService.js'; import { WebhookDeliverProcessorService } from './processors/WebhookDeliverProcessorService.js';
import { CheckExpiredMutingsProcessorService } from './processors/CheckExpiredMutingsProcessorService.js'; import { CheckExpiredMutingsProcessorService } from './processors/CheckExpiredMutingsProcessorService.js';
import { AutoDeleteNotesProcessorService } from './processors/AutoDeleteNotesProcessorService.js';
import { CleanChartsProcessorService } from './processors/CleanChartsProcessorService.js'; import { CleanChartsProcessorService } from './processors/CleanChartsProcessorService.js';
import { CleanProcessorService } from './processors/CleanProcessorService.js'; import { CleanProcessorService } from './processors/CleanProcessorService.js';
import { CleanRemoteFilesProcessorService } from './processors/CleanRemoteFilesProcessorService.js'; import { CleanRemoteFilesProcessorService } from './processors/CleanRemoteFilesProcessorService.js';
@ -52,6 +53,7 @@ import { RelationshipProcessorService } from './processors/RelationshipProcessor
ResyncChartsProcessorService, ResyncChartsProcessorService,
CleanChartsProcessorService, CleanChartsProcessorService,
CheckExpiredMutingsProcessorService, CheckExpiredMutingsProcessorService,
AutoDeleteNotesProcessorService,
CleanProcessorService, CleanProcessorService,
DeleteDriveFilesProcessorService, DeleteDriveFilesProcessorService,
ExportAccountDataProcessorService, ExportAccountDataProcessorService,

View file

@ -38,6 +38,7 @@ import { TickChartsProcessorService } from './processors/TickChartsProcessorServ
import { ResyncChartsProcessorService } from './processors/ResyncChartsProcessorService.js'; import { ResyncChartsProcessorService } from './processors/ResyncChartsProcessorService.js';
import { CleanChartsProcessorService } from './processors/CleanChartsProcessorService.js'; import { CleanChartsProcessorService } from './processors/CleanChartsProcessorService.js';
import { CheckExpiredMutingsProcessorService } from './processors/CheckExpiredMutingsProcessorService.js'; import { CheckExpiredMutingsProcessorService } from './processors/CheckExpiredMutingsProcessorService.js';
import { AutoDeleteNotesProcessorService } from './processors/AutoDeleteNotesProcessorService.js';
import { CleanProcessorService } from './processors/CleanProcessorService.js'; import { CleanProcessorService } from './processors/CleanProcessorService.js';
import { AggregateRetentionProcessorService } from './processors/AggregateRetentionProcessorService.js'; import { AggregateRetentionProcessorService } from './processors/AggregateRetentionProcessorService.js';
import { QueueLoggerService } from './QueueLoggerService.js'; import { QueueLoggerService } from './QueueLoggerService.js';
@ -118,6 +119,7 @@ export class QueueProcessorService implements OnApplicationShutdown {
private cleanChartsProcessorService: CleanChartsProcessorService, private cleanChartsProcessorService: CleanChartsProcessorService,
private aggregateRetentionProcessorService: AggregateRetentionProcessorService, private aggregateRetentionProcessorService: AggregateRetentionProcessorService,
private checkExpiredMutingsProcessorService: CheckExpiredMutingsProcessorService, private checkExpiredMutingsProcessorService: CheckExpiredMutingsProcessorService,
private autoDeleteNotesProcessorService: AutoDeleteNotesProcessorService,
private cleanProcessorService: CleanProcessorService, private cleanProcessorService: CleanProcessorService,
) { ) {
this.logger = this.queueLoggerService.logger; this.logger = this.queueLoggerService.logger;
@ -146,6 +148,7 @@ export class QueueProcessorService implements OnApplicationShutdown {
case 'cleanCharts': return this.cleanChartsProcessorService.process(); case 'cleanCharts': return this.cleanChartsProcessorService.process();
case 'aggregateRetention': return this.aggregateRetentionProcessorService.process(); case 'aggregateRetention': return this.aggregateRetentionProcessorService.process();
case 'checkExpiredMutings': return this.checkExpiredMutingsProcessorService.process(); case 'checkExpiredMutings': return this.checkExpiredMutingsProcessorService.process();
case 'autoDeleteNotes': return this.autoDeleteNotesProcessorService.process();
case 'clean': return this.cleanProcessorService.process(); case 'clean': return this.cleanProcessorService.process();
default: throw new Error(`unrecognized job type ${job.name} for system`); default: throw new Error(`unrecognized job type ${job.name} for system`);
} }

View file

@ -0,0 +1,73 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { Inject, Injectable } from '@nestjs/common';
import { In } from 'typeorm';
import { DI } from '@/di-symbols.js';
import type { UserProfilesRepository, NotesRepository } from '@/models/_.js';
import type Logger from '@/logger.js';
import { bindThis } from '@/decorators.js';
import { NoteDeleteService } from '@/core/NoteDeleteService.js';
import { IdService } from '@/core/IdService.js';
import { QueueLoggerService } from '../QueueLoggerService.js';
import type * as Bull from 'bullmq';
@Injectable()
export class AutoDeleteNotesProcessorService {
private logger: Logger;
constructor(
@Inject(DI.userProfilesRepository)
private userProfilesRepository: UserProfilesRepository,
@Inject(DI.notesRepository)
private notesRepository: NotesRepository,
@Inject(DI.userNotePiningsRepository)
private userNotePiningsRepository: UserNotePiningsRepository,
private idService: IdService,
private noteDeleteService: NoteDeleteService,
private queueLoggerService: QueueLoggerService,
) {
this.logger = this.queueLoggerService.logger.createSubLogger('auto-delete-notes');
}
@bindThis
public async process(): Promise<void> {
this.logger.info('Auto deleting old notes...');
const users = await this.userProfilesRepository.createQueryBuilder('user_profile')
.innerJoinAndSelect('user_profile.user', 'user')
.where('user.host IS NULL')
.andWhere('user_profile.autoDeleteNotes')
.getMany();
for (const user of users) {
this.logger.info(`Deleting old notes of user @${user.user.username} (id ${user.user.id})`);
const untilTime = Date.now() - (user.autoDeleteNotesMinutes * 1000 * 60);
const untilId = this.idService.gen(untilTime);
const pins = await this.userNotePiningsRepository.createQueryBuilder('user_note_pining')
.where('"userId" = :userId', { userId: user.user.id })
.getMany();
const pinnedNoteIds = pins.map((p) => p.noteId);
const notes = await this.notesRepository.createQueryBuilder('note')
.where('note."userId" = :userId', { userId: user.user.id })
.andWhere('note.id < :untilId', { untilId })
.getMany();
for (const note of notes) {
if (pinnedNoteIds.includes(note.id)) {
continue;
}
await this.noteDeleteService.delete(user, note);
}
}
this.logger.succ('Done with note auto-delete');
}
}