Merge pull request 'refactor expiring data and expire signins after 60 days' (#180) from expire-data into main
All checks were successful
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-client Pipeline was successful
ci/woodpecker/push/lint-backend Pipeline was successful
ci/woodpecker/push/test Pipeline was successful

Reviewed-on: #180
This commit is contained in:
Norm 2022-10-03 18:27:13 +00:00
commit 8ccc22bb35
8 changed files with 62 additions and 68 deletions

View file

@ -479,6 +479,7 @@ youHaveNoGroups: "You have no groups"
joinOrCreateGroup: "Get invited to a group or create your own."
noHistory: "No history available"
signinHistory: "Login history"
signinHistoryExpires: "Data about past login attempts is automatically deleted after 60 days to comply with privacy regulations."
disableAnimatedMfm: "Disable MFM with animation"
doing: "Processing..."
category: "Category"

View file

@ -74,7 +74,6 @@ export async function masterMain(): Promise<void> {
if (!envOption.noDaemons) {
import('../daemons/server-stats.js').then(x => x.serverStats());
import('../daemons/queue-stats.js').then(x => x.queueStats());
import('../daemons/janitor.js').then(x => x.janitor());
}
}

View file

@ -1,21 +0,0 @@
// TODO: 消したい
import { LessThan } from 'typeorm';
import { AttestationChallenges } from '@/models/index.js';
const interval = 30 * 60 * 1000;
/**
* Clean up database occasionally
*/
export function janitor(): void {
async function tick(): Promise<void> {
await AttestationChallenges.delete({
createdAt: LessThan(new Date(new Date().getTime() - 5 * 60 * 1000)),
});
}
tick();
setInterval(tick, interval);
}

View file

@ -314,7 +314,7 @@ export default function() {
removeOnComplete: true,
});
systemQueue.add('checkExpiredMutings', {
systemQueue.add('checkExpired', {
}, {
repeat: { cron: '*/5 * * * *' },
removeOnComplete: true,

View file

@ -1,30 +0,0 @@
import Bull from 'bull';
import { In } from 'typeorm';
import { Mutings } from '@/models/index.js';
import { publishUserEvent } from '@/services/stream.js';
import { queueLogger } from '@/queue/logger.js';
const logger = queueLogger.createSubLogger('check-expired-mutings');
export async function checkExpiredMutings(job: Bull.Job<Record<string, unknown>>, done: any): Promise<void> {
logger.info('Checking expired mutings...');
const expired = await Mutings.createQueryBuilder('muting')
.where('muting.expiresAt IS NOT NULL')
.andWhere('muting.expiresAt < :now', { now: new Date() })
.innerJoinAndSelect('muting.mutee', 'mutee')
.getMany();
if (expired.length > 0) {
await Mutings.delete({
id: In(expired.map(m => m.id)),
});
for (const m of expired) {
publishUserEvent(m.muterId, 'unmute', m.mutee!);
}
}
logger.succ('All expired mutings checked.');
done();
}

View file

@ -0,0 +1,41 @@
import Bull from 'bull';
import { In, LessThan } from 'typeorm';
import { AttestationChallenges, Mutings, Signins } from '@/models/index.js';
import { publishUserEvent } from '@/services/stream.js';
import { MINUTE, DAY } from '@/const.js';
import { queueLogger } from '@/queue/logger.js';
const logger = queueLogger.createSubLogger('check-expired');
export async function checkExpired(job: Bull.Job<Record<string, unknown>>, done: any): Promise<void> {
logger.info('Checking expired data...');
const expiredMutings = await Mutings.createQueryBuilder('muting')
.where('muting.expiresAt IS NOT NULL')
.andWhere('muting.expiresAt < :now', { now: new Date() })
.innerJoinAndSelect('muting.mutee', 'mutee')
.getMany();
if (expiredMutings.length > 0) {
await Mutings.delete({
id: In(expiredMutings.map(m => m.id)),
});
for (const m of expiredMutings) {
publishUserEvent(m.muterId, 'unmute', m.mutee!);
}
}
await Signins.delete({
// 60 days, or roughly equal to two months
createdAt: LessThan(new Date(new Date().getTime() - 60 * DAY)),
});
await AttestationChallenges.delete({
createdAt: LessThan(new Date(new Date().getTime() - 5 * MINUTE)),
});
logger.succ('Deleted expired mutes, signins and attestation challenges.');
done();
}

View file

@ -2,13 +2,13 @@ import Bull from 'bull';
import { tickCharts } from './tick-charts.js';
import { resyncCharts } from './resync-charts.js';
import { cleanCharts } from './clean-charts.js';
import { checkExpiredMutings } from './check-expired-mutings.js';
import { checkExpired } from './check-expired.js';
const jobs = {
tickCharts,
resyncCharts,
cleanCharts,
checkExpiredMutings,
checkExpired,
} as Record<string, Bull.ProcessCallbackFunction<Record<string, unknown>> | Bull.ProcessPromiseFunction<Record<string, unknown>>>;
export default function(dbQueue: Bull.Queue<Record<string, unknown>>) {

View file

@ -12,20 +12,24 @@
<FormSection>
<template #label>{{ i18n.ts.signinHistory }}</template>
<MkPagination :pagination="pagination">
<template #default="{items}">
<div>
<div v-for="item in items" :key="item.id" v-panel class="timnmucd">
<header>
<i v-if="item.success" class="fas fa-check icon succ"></i>
<i v-else class="fas fa-times-circle icon fail"></i>
<code class="ip _monospace">{{ item.ip }}</code>
<MkTime :time="item.createdAt" class="time"/>
</header>
<FormSlot>
<MkPagination :pagination="pagination">
<template #default="{items}">
<div>
<div v-for="item in items" :key="item.id" v-panel class="timnmucd">
<header>
<i v-if="item.success" class="fas fa-check icon succ"></i>
<i v-else class="fas fa-times-circle icon fail"></i>
<code class="ip _monospace">{{ item.ip }}</code>
<MkTime :time="item.createdAt" class="time"/>
</header>
</div>
</div>
</div>
</template>
</MkPagination>
</template>
<template #empty>{{ i18n.ts.noMoreHistory }}</template>
</MkPagination>
<template #caption>{{ i18n.ts.signinHistoryExpires }}</template>
</FormSlot>
</FormSection>
<FormSection>