File tree Expand file tree Collapse file tree
packages/features/eventtypes/repositories Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments