Skip to content

Commit 95a4567

Browse files
authored
perf: use compound key (calcom#25970)
1 parent d8ddb46 commit 95a4567

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

packages/features/eventtypes/repositories/eventTypeRepository.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,11 +1123,40 @@ export class EventTypeRepository {
11231123
}
11241124

11251125
async findFirstEventTypeId({ slug, teamId, userId }: { slug: string; teamId?: number; userId?: number }) {
1126+
// Use compound unique keys when available for optimal performance
1127+
// Note: teamId and userId are mutually exclusive - never both provided
1128+
if (teamId) {
1129+
return this.prismaClient.eventType.findUnique({
1130+
where: {
1131+
teamId_slug: {
1132+
teamId,
1133+
slug,
1134+
},
1135+
},
1136+
select: {
1137+
id: true,
1138+
},
1139+
});
1140+
}
1141+
1142+
if (userId) {
1143+
return this.prismaClient.eventType.findUnique({
1144+
where: {
1145+
userId_slug: {
1146+
userId,
1147+
slug,
1148+
},
1149+
},
1150+
select: {
1151+
id: true,
1152+
},
1153+
});
1154+
}
1155+
1156+
// Fallback to findFirst if neither is provided (shouldn't happen in practice)
11261157
return this.prismaClient.eventType.findFirst({
11271158
where: {
11281159
slug,
1129-
...(teamId ? { teamId } : {}),
1130-
...(userId ? { userId } : {}),
11311160
},
11321161
select: {
11331162
id: true,

0 commit comments

Comments
 (0)