forked from FoundKeyGang/FoundKey
Merge pull request 'refactor expiring data and expire signins after 60 days' (#180) from expire-data into main
Reviewed-on: FoundKeyGang/FoundKey#180
This commit is contained in:
commit
8ccc22bb35
8 changed files with 62 additions and 68 deletions
|
@ -479,6 +479,7 @@ youHaveNoGroups: "You have no groups"
|
||||||
joinOrCreateGroup: "Get invited to a group or create your own."
|
joinOrCreateGroup: "Get invited to a group or create your own."
|
||||||
noHistory: "No history available"
|
noHistory: "No history available"
|
||||||
signinHistory: "Login history"
|
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"
|
disableAnimatedMfm: "Disable MFM with animation"
|
||||||
doing: "Processing..."
|
doing: "Processing..."
|
||||||
category: "Category"
|
category: "Category"
|
||||||
|
|
|
@ -74,7 +74,6 @@ export async function masterMain(): Promise<void> {
|
||||||
if (!envOption.noDaemons) {
|
if (!envOption.noDaemons) {
|
||||||
import('../daemons/server-stats.js').then(x => x.serverStats());
|
import('../daemons/server-stats.js').then(x => x.serverStats());
|
||||||
import('../daemons/queue-stats.js').then(x => x.queueStats());
|
import('../daemons/queue-stats.js').then(x => x.queueStats());
|
||||||
import('../daemons/janitor.js').then(x => x.janitor());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -314,7 +314,7 @@ export default function() {
|
||||||
removeOnComplete: true,
|
removeOnComplete: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
systemQueue.add('checkExpiredMutings', {
|
systemQueue.add('checkExpired', {
|
||||||
}, {
|
}, {
|
||||||
repeat: { cron: '*/5 * * * *' },
|
repeat: { cron: '*/5 * * * *' },
|
||||||
removeOnComplete: true,
|
removeOnComplete: true,
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
|
@ -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();
|
||||||
|
}
|
|
@ -2,13 +2,13 @@ import Bull from 'bull';
|
||||||
import { tickCharts } from './tick-charts.js';
|
import { tickCharts } from './tick-charts.js';
|
||||||
import { resyncCharts } from './resync-charts.js';
|
import { resyncCharts } from './resync-charts.js';
|
||||||
import { cleanCharts } from './clean-charts.js';
|
import { cleanCharts } from './clean-charts.js';
|
||||||
import { checkExpiredMutings } from './check-expired-mutings.js';
|
import { checkExpired } from './check-expired.js';
|
||||||
|
|
||||||
const jobs = {
|
const jobs = {
|
||||||
tickCharts,
|
tickCharts,
|
||||||
resyncCharts,
|
resyncCharts,
|
||||||
cleanCharts,
|
cleanCharts,
|
||||||
checkExpiredMutings,
|
checkExpired,
|
||||||
} as Record<string, Bull.ProcessCallbackFunction<Record<string, unknown>> | Bull.ProcessPromiseFunction<Record<string, unknown>>>;
|
} as Record<string, Bull.ProcessCallbackFunction<Record<string, unknown>> | Bull.ProcessPromiseFunction<Record<string, unknown>>>;
|
||||||
|
|
||||||
export default function(dbQueue: Bull.Queue<Record<string, unknown>>) {
|
export default function(dbQueue: Bull.Queue<Record<string, unknown>>) {
|
||||||
|
|
|
@ -12,20 +12,24 @@
|
||||||
|
|
||||||
<FormSection>
|
<FormSection>
|
||||||
<template #label>{{ i18n.ts.signinHistory }}</template>
|
<template #label>{{ i18n.ts.signinHistory }}</template>
|
||||||
<MkPagination :pagination="pagination">
|
<FormSlot>
|
||||||
<template #default="{items}">
|
<MkPagination :pagination="pagination">
|
||||||
<div>
|
<template #default="{items}">
|
||||||
<div v-for="item in items" :key="item.id" v-panel class="timnmucd">
|
<div>
|
||||||
<header>
|
<div v-for="item in items" :key="item.id" v-panel class="timnmucd">
|
||||||
<i v-if="item.success" class="fas fa-check icon succ"></i>
|
<header>
|
||||||
<i v-else class="fas fa-times-circle icon fail"></i>
|
<i v-if="item.success" class="fas fa-check icon succ"></i>
|
||||||
<code class="ip _monospace">{{ item.ip }}</code>
|
<i v-else class="fas fa-times-circle icon fail"></i>
|
||||||
<MkTime :time="item.createdAt" class="time"/>
|
<code class="ip _monospace">{{ item.ip }}</code>
|
||||||
</header>
|
<MkTime :time="item.createdAt" class="time"/>
|
||||||
|
</header>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</template>
|
||||||
</template>
|
<template #empty>{{ i18n.ts.noMoreHistory }}</template>
|
||||||
</MkPagination>
|
</MkPagination>
|
||||||
|
<template #caption>{{ i18n.ts.signinHistoryExpires }}</template>
|
||||||
|
</FormSlot>
|
||||||
</FormSection>
|
</FormSection>
|
||||||
|
|
||||||
<FormSection>
|
<FormSection>
|
||||||
|
|
Loading…
Reference in a new issue