feat: add member cache; handle all role changes with RoleManagerPlugin; exit gracefully

This commit is contained in:
Dragory 2023-05-07 17:56:55 +03:00
parent fd60a09947
commit fa50110766
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
48 changed files with 755 additions and 264 deletions

View file

@ -0,0 +1,29 @@
import moment from "moment-timezone";
import { getRepository, Repository } from "typeorm";
import { DAYS } from "../utils";
import { BaseRepository } from "./BaseRepository";
import { MemberCacheItem } from "./entities/MemberCacheItem";
const STALE_PERIOD = 90 * DAYS;
export class MemberCache extends BaseRepository {
#memberCache: Repository<MemberCacheItem>;
constructor() {
super();
this.#memberCache = getRepository(MemberCacheItem);
}
async deleteStaleData(): Promise<void> {
const cutoff = moment().subtract(STALE_PERIOD, "ms").format("YYYY-MM-DD");
await this.#memberCache.createQueryBuilder().where("last_seen < :cutoff", { cutoff }).delete().execute();
}
async deleteMarkedToBeDeletedEntries(): Promise<void> {
await this.#memberCache
.createQueryBuilder()
.where("delete_at IS NOT NULL AND delete_at <= NOW()")
.delete()
.execute();
}
}