diff --git a/backend/src/index.ts b/backend/src/index.ts index 789b9606..a8d4236b 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -31,6 +31,7 @@ import { runExpiringVCAlertsLoop } from "./data/loops/expiringVCAlertsLoop"; import { runExpiredArchiveDeletionLoop } from "./data/loops/expiredArchiveDeletionLoop"; import { runSavedMessageCleanupLoop } from "./data/loops/savedMessageCleanupLoop"; import { performance } from "perf_hooks"; +import { setProfiler } from "./profiler"; if (!process.env.KEY) { // tslint:disable-next-line:no-console @@ -363,6 +364,8 @@ connect().then(async () => { runSavedMessageCleanupLoop(); }); + setProfiler(bot.profiler); + bot.initialize(); logger.info("Bot Initialized"); logger.info("Logging in..."); diff --git a/backend/src/utils.ts b/backend/src/utils.ts index f6ea6c91..32b7f548 100644 --- a/backend/src/utils.ts +++ b/backend/src/utils.ts @@ -45,6 +45,8 @@ import { sendDM } from "./utils/sendDM"; import { waitForButtonConfirm } from "./utils/waitForInteraction"; import { decodeAndValidateStrict, StrictValidationError } from "./validatorUtils"; import { z, ZodError } from "zod"; +import { getProfiler } from "./profiler"; +import { performance } from "perf_hooks"; const fsp = fs.promises; @@ -1294,8 +1296,13 @@ export function resolveUserId(bot: Client, value: string) { // A non-mention, full username? const usernameMatch = value.match(/^@?([^#]+)#(\d{4})$/); if (usernameMatch) { + const profiler = getProfiler(); + const start = performance.now(); const user = bot.users.cache.find((u) => u.username === usernameMatch[1] && u.discriminator === usernameMatch[2]); - if (user) return user.id; + profiler?.addDataPoint("utils:resolveUserId:usernameMatch", performance.now() - start); + if (user) { + return user.id; + } } return null;