Skip to content

Commit c1be922

Browse files
authored
perf: Workflows are taking too long to load (calcom#25705)
* perf: workflows are too slow * Refactor eventTypeRepository for improved clarity * Reintroduce ErrorCode and ErrorWithCode imports
1 parent 967bba1 commit c1be922

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

packages/features/eventtypes/repositories/eventTypeRepository.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,15 @@ export class EventTypeRepository {
305305
) {
306306
if (!upId) return [];
307307
const lookupTarget = ProfileRepository.getLookupTarget(upId);
308-
const profileId = lookupTarget.type === LookupTarget.User ? null : lookupTarget.id;
308+
let profileId: number | null = null;
309+
if (lookupTarget.type === LookupTarget.Profile) {
310+
if ("uid" in lookupTarget && lookupTarget.uid) {
311+
const profile = await ProfileRepository.findByUid(lookupTarget.uid);
312+
profileId = profile?.id ?? null;
313+
} else if ("id" in lookupTarget && lookupTarget.id !== undefined) {
314+
profileId = lookupTarget.id;
315+
}
316+
}
309317
const select = {
310318
...eventTypeSelect,
311319
hashedLink: hashedLinkSelect,

packages/features/profile/repositories/ProfileRepository.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,13 @@ export class ProfileRepository {
140140
bufferTime: user.bufferTime,
141141
};
142142
}
143-
143+
/**
144+
* Parses a Universal Profile ID (upId) into a lookup target.
145+
* - "usr-{id}" → { type: User, id }
146+
* - "prof-{uuid}" → { type: Profile, uid } (no `id`)
147+
* - "{numericId}" → { type: Profile, id } (legacy)
148+
* For profiles, always check for `uid` first; `id` may be undefined.
149+
*/
144150
static getLookupTarget(upId: UpId) {
145151
if (upId.trim() === "") {
146152
return {

0 commit comments

Comments
 (0)