perf(db): add missing indexes, fix N+1 batch delete, add pagination limits
- Add indexes on Resource(blueprintId, roleId), DemandRequirement(roleId),
Assignment(roleId) — commonly filtered FK columns that were missing indexes
- Replace N+1 batch delete pattern (2N queries) with findAllocationEntries()
that does 2 total queries via findMany({ id: { in: ids } })
- Add take/skip pagination with default limit of 500 to listDemands and
listAssignments to prevent unbounded result sets
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -914,6 +914,8 @@ model Resource {
|
||||
@@index([orgUnitId])
|
||||
@@index([resourceType])
|
||||
@@index([managementLevelGroupId])
|
||||
@@index([blueprintId])
|
||||
@@index([roleId])
|
||||
@@map("resources")
|
||||
}
|
||||
|
||||
@@ -1323,6 +1325,7 @@ model DemandRequirement {
|
||||
@@index([startDate, endDate])
|
||||
@@index([status])
|
||||
@@index([projectId, status, startDate])
|
||||
@@index([roleId])
|
||||
@@map("demand_requirements")
|
||||
}
|
||||
|
||||
@@ -1362,6 +1365,7 @@ model Assignment {
|
||||
@@index([projectId, status, startDate, endDate])
|
||||
@@index([resourceId, status, endDate])
|
||||
@@index([projectId, status, endDate])
|
||||
@@index([roleId])
|
||||
@@map("assignments")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user