perf: use compound key (#25970)

This commit is contained in:
sean-brydon
2025-12-20 14:57:55 +00:00
committed by GitHub
parent d8ddb466b0
commit 95a4567f35
@@ -1123,11 +1123,40 @@ export class EventTypeRepository {
}
async findFirstEventTypeId({ slug, teamId, userId }: { slug: string; teamId?: number; userId?: number }) {
// Use compound unique keys when available for optimal performance
// Note: teamId and userId are mutually exclusive - never both provided
if (teamId) {
return this.prismaClient.eventType.findUnique({
where: {
teamId_slug: {
teamId,
slug,
},
},
select: {
id: true,
},
});
}
if (userId) {
return this.prismaClient.eventType.findUnique({
where: {
userId_slug: {
userId,
slug,
},
},
select: {
id: true,
},
});
}
// Fallback to findFirst if neither is provided (shouldn't happen in practice)
return this.prismaClient.eventType.findFirst({
where: {
slug,
...(teamId ? { teamId } : {}),
...(userId ? { userId } : {}),
},
select: {
id: true,