perf(api): eliminate N+1 queries, add query guards and missing indexes
- Notification fan-out: replace sequential for loops with Promise.all (allocation-effects, notification-broadcast, create-notification) - Public holiday batch: group resources by location combo, resolve holidays once per group, replace per-holiday delete/findFirst/create with 3 batched queries (~18K → ~5 queries) - Add take guards to unbounded findMany calls (resource-analytics: 5000, resource-marketplace: 2000, resource-capacity: 1000, chargeability-report: 2000) - auto-staffing: add select with only needed fields + take: 5000 - schema.prisma: add 5 missing indexes (ManagementLevel.groupId, Blueprint.isActive/target, Comment.parentId, Vacation.requestedById, Resource.managementLevelGroupId) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -751,6 +751,7 @@ model ManagementLevel {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@index([groupId])
|
||||
@@map("management_levels")
|
||||
}
|
||||
|
||||
@@ -778,6 +779,8 @@ model Blueprint {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@index([isActive])
|
||||
@@index([target])
|
||||
@@map("blueprints")
|
||||
}
|
||||
|
||||
@@ -904,6 +907,7 @@ model Resource {
|
||||
@@index([countryId])
|
||||
@@index([orgUnitId])
|
||||
@@index([resourceType])
|
||||
@@index([managementLevelGroupId])
|
||||
@@map("resources")
|
||||
}
|
||||
|
||||
@@ -1347,6 +1351,8 @@ model Assignment {
|
||||
@@index([status])
|
||||
@@index([resourceId, status, startDate])
|
||||
@@index([projectId, startDate, endDate])
|
||||
@@index([status, startDate, endDate])
|
||||
@@index([projectId, status, startDate, endDate])
|
||||
@@map("assignments")
|
||||
}
|
||||
|
||||
@@ -1386,6 +1392,7 @@ model Vacation {
|
||||
@@index([startDate, endDate])
|
||||
@@index([status])
|
||||
@@index([resourceId, status, startDate, endDate])
|
||||
@@index([requestedById])
|
||||
@@map("vacations")
|
||||
}
|
||||
|
||||
@@ -1649,6 +1656,7 @@ model Comment {
|
||||
|
||||
@@index([entityType, entityId])
|
||||
@@index([authorId])
|
||||
@@index([parentId])
|
||||
@@map("comments")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user