debug: track resolveUserId username match performance

This commit is contained in:
Dragory 2021-10-26 22:40:31 +03:00
parent 23fba8cdcf
commit 2fd5bb3d17
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
2 changed files with 11 additions and 1 deletions

View file

@ -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;