From c1be922ee12a191f8ba67180d786872107f1ce16 Mon Sep 17 00:00:00 2001 From: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Date: Mon, 8 Dec 2025 18:31:46 +0530 Subject: [PATCH] perf: Workflows are taking too long to load (#25705) * perf: workflows are too slow * Refactor eventTypeRepository for improved clarity * Reintroduce ErrorCode and ErrorWithCode imports --- .../eventtypes/repositories/eventTypeRepository.ts | 10 +++++++++- .../features/profile/repositories/ProfileRepository.ts | 8 +++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/features/eventtypes/repositories/eventTypeRepository.ts b/packages/features/eventtypes/repositories/eventTypeRepository.ts index 6be695e9d0..983522cce4 100644 --- a/packages/features/eventtypes/repositories/eventTypeRepository.ts +++ b/packages/features/eventtypes/repositories/eventTypeRepository.ts @@ -305,7 +305,15 @@ export class EventTypeRepository { ) { if (!upId) return []; const lookupTarget = ProfileRepository.getLookupTarget(upId); - const profileId = lookupTarget.type === LookupTarget.User ? null : lookupTarget.id; + let profileId: number | null = null; + if (lookupTarget.type === LookupTarget.Profile) { + if ("uid" in lookupTarget && lookupTarget.uid) { + const profile = await ProfileRepository.findByUid(lookupTarget.uid); + profileId = profile?.id ?? null; + } else if ("id" in lookupTarget && lookupTarget.id !== undefined) { + profileId = lookupTarget.id; + } + } const select = { ...eventTypeSelect, hashedLink: hashedLinkSelect, diff --git a/packages/features/profile/repositories/ProfileRepository.ts b/packages/features/profile/repositories/ProfileRepository.ts index 9cbd8688d6..59406fd798 100644 --- a/packages/features/profile/repositories/ProfileRepository.ts +++ b/packages/features/profile/repositories/ProfileRepository.ts @@ -140,7 +140,13 @@ export class ProfileRepository { bufferTime: user.bufferTime, }; } - + /** + * Parses a Universal Profile ID (upId) into a lookup target. + * - "usr-{id}" → { type: User, id } + * - "prof-{uuid}" → { type: Profile, uid } (no `id`) + * - "{numericId}" → { type: Profile, id } (legacy) + * For profiles, always check for `uid` first; `id` may be undefined. + */ static getLookupTarget(upId: UpId) { if (upId.trim() === "") { return {