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', {
|
this.systemQueue.add('autoDeleteNotes', {
|
||||||
}, {
|
}, {
|
||||||
repeat: { pattern: '*/1 * * * *' },
|
repeat: { pattern: '*/5 * * * *' },
|
||||||
removeOnComplete: true,
|
removeOnComplete: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,35 +37,38 @@ export class AutoDeleteNotesProcessorService {
|
||||||
public async process(): Promise<void> {
|
public async process(): Promise<void> {
|
||||||
this.logger.info('Auto deleting old notes...');
|
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')
|
.innerJoinAndSelect('user_profile.user', 'user')
|
||||||
.where('user.host IS NULL')
|
.where('user.host IS NULL')
|
||||||
.andWhere('user_profile.autoDeleteNotes')
|
.andWhere('user_profile.autoDeleteNotes')
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
for (const user of users) {
|
for (const userProfile of userProfiles) {
|
||||||
this.logger.info(`Deleting old notes of user @${user.user.username} (id ${user.user.id})`);
|
const user = userProfile.user;
|
||||||
const untilTime = Date.now() - (user.autoDeleteNotesMinutes * 1000 * 60);
|
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 untilId = this.idService.gen(untilTime);
|
||||||
|
|
||||||
const pins = await this.userNotePiningsRepository.createQueryBuilder('user_note_pining')
|
const pins = await this.userNotePiningsRepository.createQueryBuilder('user_note_pining')
|
||||||
.where('"userId" = :userId', { userId: user.user.id })
|
.where('"userId" = :userId', { userId: user.id })
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
const pinnedNoteIds = pins.map((p) => p.noteId);
|
const pinnedNoteIds = pins.map((p) => p.noteId);
|
||||||
|
|
||||||
const notes = await this.notesRepository.createQueryBuilder('note')
|
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 < :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();
|
.getMany();
|
||||||
|
|
||||||
for (const note of notes) {
|
for (const note of notes) {
|
||||||
if (pinnedNoteIds.includes(note.id)) {
|
if (pinnedNoteIds.includes(note.id)) {
|
||||||
|
this.logger.debug(`Skipping note ${note.id} as it is pinned`);
|
||||||
continue;
|
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