perf: Workflows are taking too long to load (#25705)

* perf: workflows are too slow

* Refactor eventTypeRepository for improved clarity

* Reintroduce ErrorCode and ErrorWithCode imports
This commit is contained in:
Anik Dhabal Babu
2025-12-08 18:31:46 +05:30
committed by GitHub
parent 967bba1e80
commit c1be922ee1
2 changed files with 16 additions and 2 deletions
@@ -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,
@@ -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 {