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