feat(mutes): clear old expired mutes for servers that have disabled the mutes plugin
This commit is contained in:
parent
66b93dd31c
commit
f00a7afab8
2 changed files with 16 additions and 1 deletions
|
@ -1,9 +1,11 @@
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { Brackets, getRepository, Repository } from "typeorm";
|
import { Brackets, getRepository, Repository } from "typeorm";
|
||||||
import { Mute } from "./entities/Mute";
|
import { Mute } from "./entities/Mute";
|
||||||
import { DBDateFormat } from "../utils";
|
import { DAYS, DBDateFormat } from "../utils";
|
||||||
import { BaseRepository } from "./BaseRepository";
|
import { BaseRepository } from "./BaseRepository";
|
||||||
|
|
||||||
|
const OLD_EXPIRED_MUTE_THRESHOLD = 7 * DAYS;
|
||||||
|
|
||||||
export class Mutes extends BaseRepository {
|
export class Mutes extends BaseRepository {
|
||||||
private mutes: Repository<Mute>;
|
private mutes: Repository<Mute>;
|
||||||
|
|
||||||
|
@ -20,4 +22,14 @@ export class Mutes extends BaseRepository {
|
||||||
.andWhere("expires_at <= :date", { date: thresholdDateStr })
|
.andWhere("expires_at <= :date", { date: thresholdDateStr })
|
||||||
.getMany();
|
.getMany();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async clearOldExpiredMutes(): Promise<void> {
|
||||||
|
const thresholdDateStr = moment.utc().subtract(OLD_EXPIRED_MUTE_THRESHOLD, "ms").format(DBDateFormat);
|
||||||
|
await this.mutes
|
||||||
|
.createQueryBuilder("mutes")
|
||||||
|
.andWhere("expires_at IS NOT NULL")
|
||||||
|
.andWhere("expires_at <= :date", { date: thresholdDateStr })
|
||||||
|
.delete()
|
||||||
|
.execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,9 @@ export async function runExpiringMutesLoop() {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("[EXPIRING MUTES LOOP] Clearing old expired mutes");
|
||||||
|
await getMutesRepository().clearOldExpiredMutes();
|
||||||
|
|
||||||
console.log("[EXPIRING MUTES LOOP] Setting timeouts for expiring mutes");
|
console.log("[EXPIRING MUTES LOOP] Setting timeouts for expiring mutes");
|
||||||
const expiringMutes = await getMutesRepository().getSoonExpiringMutes(LOOP_INTERVAL);
|
const expiringMutes = await getMutesRepository().getSoonExpiringMutes(LOOP_INTERVAL);
|
||||||
for (const mute of expiringMutes) {
|
for (const mute of expiringMutes) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue