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
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:
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,6 +12,7 @@
|
||||||
|
|
||||||
<FormSection>
|
<FormSection>
|
||||||
<template #label>{{ i18n.ts.signinHistory }}</template>
|
<template #label>{{ i18n.ts.signinHistory }}</template>
|
||||||
|
<FormSlot>
|
||||||
<MkPagination :pagination="pagination">
|
<MkPagination :pagination="pagination">
|
||||||
<template #default="{items}">
|
<template #default="{items}">
|
||||||
<div>
|
<div>
|
||||||
|
@ -25,7 +26,10 @@
|
||||||
</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