From d3de1c9597c8e3e653de923fff7d548fed24b9ac Mon Sep 17 00:00:00 2001 From: tippfehlr Date: Sun, 10 Mar 2024 00:29:20 +0100 Subject: [PATCH] perf: cache limits and sweeper rules --- src/modules/bot.ts | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/modules/bot.ts b/src/modules/bot.ts index 2e27532..d1d6be1 100644 --- a/src/modules/bot.ts +++ b/src/modules/bot.ts @@ -1,5 +1,5 @@ import { createHash } from 'crypto'; -import Discord, { ActivityType, Events, GatewayIntentBits, PermissionsBitField } from 'discord.js'; +import Discord, { ActivityType, Events, GatewayIntentBits, Options, PermissionsBitField } from 'discord.js'; import { DBActiveTemporaryRoles, @@ -22,7 +22,35 @@ export const client = new Discord.Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildPresences, - ] + ], + makeCache: Options.cacheWithLimits({ + ...Options.DefaultMakeCacheSettings, + MessageManager: 0, + UserManager: { + maxSize: 5000, + keepOverLimit: user => user.id === user.client.user.id, + }, + GuildMemberManager: { + maxSize: 1000, + keepOverLimit: member => member.id === member.client.user.id, + }, + PresenceManager: 1000, + }), + sweepers: { + ...Options.DefaultSweeperSettings, + users: { + interval: 30 * 60, // 30 minutes + filter: () => user => user.id !== user.client.user.id, // don’t remove the client’s user + }, + presences: { + interval: 30 * 60, + filter: () => () => true, // remove all presences + }, + guildMembers: { + interval: 30 * 60, + filter: () => member => member.id !== member.client.user.id, + }, + }, }); export let commandHandler: CommandHandler;