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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,12 +11,12 @@
|
|||
</MkInput>
|
||||
<MkFolder>
|
||||
<template #label>{{ i18n.ts.selectFromPresets }}</template>
|
||||
<FormSplit :minWidth="100">
|
||||
<MkButton @click="setThreshold(WEEK_MINUTES)" inline small>{{ i18n.ts.oneWeek }}</MkButton>
|
||||
<MkButton @click="setThreshold(MONTH_MINUTES)" inline small>{{ i18n.ts.oneMonth }}</MkButton>
|
||||
<MkButton @click="setThreshold(YEAR_MINUTES)" inline small>{{ i18n.ts.oneYear }}</MkButton>
|
||||
</FormSplit>
|
||||
</MkFolder>
|
||||
<FormSplit :minWidth="100">
|
||||
<MkButton @click="setThreshold(WEEK_MINUTES)" inline small>{{ i18n.ts.oneWeek }}</MkButton>
|
||||
<MkButton @click="setThreshold(MONTH_MINUTES)" inline small>{{ i18n.ts.oneMonth }}</MkButton>
|
||||
<MkButton @click="setThreshold(YEAR_MINUTES)" inline small>{{ i18n.ts.oneYear }}</MkButton>
|
||||
</FormSplit>
|
||||
</MkFolder>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -50,17 +50,17 @@ function setThreshold(value) {
|
|||
|
||||
async function save() {
|
||||
if (enable.value) {
|
||||
const { canceled } = await os.confirm({
|
||||
type: 'warning',
|
||||
text: 'This action may immediately delete notes older than the threshold value! Click ok to confirm.',
|
||||
});
|
||||
const { canceled } = await os.confirm({
|
||||
type: 'warning',
|
||||
text: 'This action may immediately delete notes older than the threshold value! Click ok to confirm.',
|
||||
});
|
||||
|
||||
if (canceled) return;
|
||||
if (canceled) return;
|
||||
}
|
||||
|
||||
misskeyApi('i/update', {
|
||||
autoDeleteNotes: !!enable.value,
|
||||
autoDeleteNotesMinutes: threshold.value,
|
||||
autoDeleteNotes: !!enable.value,
|
||||
autoDeleteNotesMinutes: threshold.value,
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue