Skip to content

Commit 5bf07f2

Browse files
committed
chore: insightful debug logging
1 parent 01f34ac commit 5bf07f2

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

packages/bot/src/util/getUserGuilds.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ import { PrismaClient } from '@prisma/client';
22
import type { Guild, Snowflake } from 'discord.js';
33
import { Client, Collection } from 'discord.js';
44
import { container } from 'tsyringe';
5+
import { logger } from './logger.js';
56

67
export const ENABLED_CACHED_GUILDS = new Map<Snowflake, boolean>();
78

89
export async function getUserGuilds(userId: string): Promise<Collection<string, Guild>> {
910
const client = container.resolve(Client);
1011
const prisma = container.resolve(PrismaClient);
1112

13+
const cachedInGuilds = client.guilds.cache.reduce((acc, guild) => acc + (guild.members.cache.has(userId) ? 1 : 0), 0);
14+
logger.debug({ userId, enabledCacheSize: ENABLED_CACHED_GUILDS.size, cachedInGuilds }, 'Fetching guilds for user');
15+
1216
const results = await Promise.all(
1317
Array.from(client.guilds.cache.values(), async (guild) =>
1418
guild.members

0 commit comments

Comments
 (0)