Compare commits
2 commits
bef78535c9
...
d60344dfac
Author | SHA1 | Date | |
---|---|---|---|
d60344dfac | |||
fc1727870c |
3 changed files with 25 additions and 22 deletions
|
@ -72,7 +72,7 @@ export class QueueService {
|
|||
|
||||
this.systemQueue.add('autoDeleteNotes', {
|
||||
}, {
|
||||
repeat: { pattern: '*/1 * * * *' },
|
||||
repeat: { pattern: '*/5 * * * *' },
|
||||
removeOnComplete: true,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -37,35 +37,38 @@ export class AutoDeleteNotesProcessorService {
|
|||
public async process(): Promise<void> {
|
||||
this.logger.info('Auto deleting old notes...');
|
||||
|
||||
const users = await this.userProfilesRepository.createQueryBuilder('user_profile')
|
||||
const userProfiles = 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);
|
||||
for (const userProfile of userProfiles) {
|
||||
const user = userProfile.user;
|
||||
this.logger.debug(`Deleting old notes of user @${user.username} (id ${user.id})`);
|
||||
const untilTime = Date.now() - (userProfile.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 })
|
||||
.where('"userId" = :userId', { userId: 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 })
|
||||
.where('note."userId" = :userId', { userId: user.id })
|
||||
.andWhere('note.id < :untilId', { untilId })
|
||||
.andWhere('note.id NOT IN (SELECT "noteId" FROM note_favorite WHERE "userId" = :userId)');
|
||||
.andWhere('note.id NOT IN (SELECT "noteId" FROM note_favorite WHERE "userId" = :userId)')
|
||||
.getMany();
|
||||
|
||||
for (const note of notes) {
|
||||
if (pinnedNoteIds.includes(note.id)) {
|
||||
this.logger.debug(`Skipping note ${note.id} as it is pinned`);
|
||||
continue;
|
||||
}
|
||||
|
||||
await this.noteDeleteService.delete(user, note);
|
||||
this.logger.debug(`Deleting note ${note.id}`);
|
||||
await this.noteDeleteService.delete(user, note, false, user);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue