forked from FoundKeyGang/FoundKey
refactor checkExpired to use Promise.all
This commit is contained in:
parent
bed8286175
commit
7c9e118ff1
1 changed files with 38 additions and 41 deletions
|
@ -10,12 +10,17 @@ const logger = queueLogger.createSubLogger('check-expired');
|
||||||
export async function checkExpired(job: Bull.Job<Record<string, unknown>>, done: any): Promise<void> {
|
export async function checkExpired(job: Bull.Job<Record<string, unknown>>, done: any): Promise<void> {
|
||||||
logger.info('Checking expired data...');
|
logger.info('Checking expired data...');
|
||||||
|
|
||||||
const expiredMutings = await Mutings.createQueryBuilder('muting')
|
const OlderThan = (millis: number) => {
|
||||||
|
return LessThan(new Date(new Date().getTime() - millis));
|
||||||
|
};
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
Mutings.createQueryBuilder('muting')
|
||||||
.where('muting.expiresAt IS NOT NULL')
|
.where('muting.expiresAt IS NOT NULL')
|
||||||
.andWhere('muting.expiresAt < :now', { now: new Date() })
|
.andWhere('muting.expiresAt < :now', { now: new Date() })
|
||||||
.innerJoinAndSelect('muting.mutee', 'mutee')
|
.innerJoinAndSelect('muting.mutee', 'mutee')
|
||||||
.getMany();
|
.getMany()
|
||||||
|
.then(async (expiredMutings) => {
|
||||||
if (expiredMutings.length > 0) {
|
if (expiredMutings.length > 0) {
|
||||||
await Mutings.delete({
|
await Mutings.delete({
|
||||||
id: In(expiredMutings.map(m => m.id)),
|
id: In(expiredMutings.map(m => m.id)),
|
||||||
|
@ -25,37 +30,29 @@ export async function checkExpired(job: Bull.Job<Record<string, unknown>>, done:
|
||||||
publishUserEvent(m.muterId, 'unmute', m.mutee!);
|
publishUserEvent(m.muterId, 'unmute', m.mutee!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}),
|
||||||
const OlderThan = (millis: number) => {
|
Signins.delete({
|
||||||
return LessThan(new Date(new Date().getTime() - millis));
|
|
||||||
};
|
|
||||||
|
|
||||||
await Signins.delete({
|
|
||||||
createdAt: OlderThan(2 * MONTH),
|
createdAt: OlderThan(2 * MONTH),
|
||||||
});
|
}),
|
||||||
|
AttestationChallenges.delete({
|
||||||
await AttestationChallenges.delete({
|
|
||||||
createdAt: OlderThan(5 * MINUTE),
|
createdAt: OlderThan(5 * MINUTE),
|
||||||
});
|
}),
|
||||||
|
PasswordResetRequests.delete({
|
||||||
await PasswordResetRequests.delete({
|
|
||||||
// this timing should be the same as in @/server/api/endpoints/reset-password.ts
|
// this timing should be the same as in @/server/api/endpoints/reset-password.ts
|
||||||
createdAt: OlderThan(30 * MINUTE),
|
createdAt: OlderThan(30 * MINUTE),
|
||||||
});
|
}),
|
||||||
|
AuthSessions.delete({
|
||||||
await AuthSessions.delete({
|
|
||||||
createdAt: OlderThan(15 * MINUTE),
|
createdAt: OlderThan(15 * MINUTE),
|
||||||
});
|
}),
|
||||||
|
Notifications.delete({
|
||||||
await Notifications.delete({
|
|
||||||
isRead: true,
|
isRead: true,
|
||||||
createdAt: OlderThan(3 * MONTH),
|
createdAt: OlderThan(3 * MONTH),
|
||||||
});
|
}),
|
||||||
|
Users.delete({
|
||||||
await Users.delete({
|
|
||||||
// delete users where the deletion status reference count has come down to zero
|
// delete users where the deletion status reference count has come down to zero
|
||||||
isDeleted: 0,
|
isDeleted: 0,
|
||||||
});
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
logger.succ('Deleted expired data.');
|
logger.succ('Deleted expired data.');
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue