mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-07 02:57:20 +00:00
feat: add member cache; handle all role changes with RoleManagerPlugin; exit gracefully
This commit is contained in:
parent
fd60a09947
commit
fa50110766
48 changed files with 755 additions and 264 deletions
29
backend/src/data/MemberCache.ts
Normal file
29
backend/src/data/MemberCache.ts
Normal 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();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue