From 39397ed0b58cba04cd4f09be66c7414f1a6e8b89 Mon Sep 17 00:00:00 2001 From: hzmi Date: Wed, 21 Feb 2024 15:15:48 +0700 Subject: [PATCH] feat(GuildCreateListener): add GUILD_CREATE_GC_EVERY option (#360) --- services/kanao-gateway/.example.env | 6 +++++- .../src/Listeners/Caches/Guilds/GuildCreateListener.ts | 4 ++-- services/kanao-gateway/src/config.ts | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/services/kanao-gateway/.example.env b/services/kanao-gateway/.example.env index 578f18db..28e04978 100644 --- a/services/kanao-gateway/.example.env +++ b/services/kanao-gateway/.example.env @@ -40,4 +40,8 @@ STORE_LOGS=true LOKI_HOST=http://localhost:3100 # (optional) REPLICA_ID=0 -REPLICA_COUNT=1 \ No newline at end of file +REPLICA_COUNT=1 + +# Do a garbage collection on guildCreate after x times +# Useful on startups +GUILD_CREATE_GC_EVERY= \ No newline at end of file diff --git a/services/kanao-gateway/src/Listeners/Caches/Guilds/GuildCreateListener.ts b/services/kanao-gateway/src/Listeners/Caches/Guilds/GuildCreateListener.ts index 1a48891c..9406965b 100644 --- a/services/kanao-gateway/src/Listeners/Caches/Guilds/GuildCreateListener.ts +++ b/services/kanao-gateway/src/Listeners/Caches/Guilds/GuildCreateListener.ts @@ -7,11 +7,11 @@ import { GatewayDispatchEvents } from "discord-api-types/v10"; import { sql } from "drizzle-orm"; import type { ListenerContext } from "../../../Stores/Listener.js"; import { Listener } from "../../../Stores/Listener.js"; -import { clientId, stateChannels, stateRoles } from "../../../config.js"; +import { clientId, guildCreateGcEvery, stateChannels, stateRoles } from "../../../config.js"; export class GuildCreateListener extends Listener { public count = 0; - public gcEvery = 50; + public gcEvery = guildCreateGcEvery; public constructor(context: ListenerContext) { super(context, { event: GatewayDispatchEvents.GuildCreate diff --git a/services/kanao-gateway/src/config.ts b/services/kanao-gateway/src/config.ts index 558f0ed9..2a2db5aa 100644 --- a/services/kanao-gateway/src/config.ts +++ b/services/kanao-gateway/src/config.ts @@ -79,3 +79,5 @@ export const replicaId = hostname(); export const replicaCount = Number(process.env.GATEWAY_REPLICA_COUNT ?? "1"); export const databaseUrl = process.env.DATABASE_GATEWAY_URL ?? process.env.DATABASE_URL!; + +export const guildCreateGcEvery = Number(process.env.GUILD_CREATE_GC_EVERY ?? 50);