perf(api): add explicit Prisma selects on hot read paths

Replaces full model includes with field-scoped selects on the resource
list (listStaff) query. Avoids fetching large JSONB columns
(availability, valueScoreBreakdown) and unused scalar fields (aiSummary,
portfolioUrl, fte, resourceType, postalCode, etc.) when only
identity/rate fields are needed.

Adds RESOURCE_LIST_SELECT constant to packages/api/src/db/selects.ts
covering all fields actually consumed by ResourcesClient, FillOpenDemandModal,
EstimateWizard, EstimateWorkspaceDraftEditor, and ScenarioPlanner.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-09 19:24:55 +02:00
parent d3bfa8ca98
commit 6f3bdd81e8
2 changed files with 41 additions and 4 deletions
+31
View File
@@ -1,3 +1,34 @@
export const ROLE_BRIEF_SELECT = { id: true, name: true, color: true } as const;
export const PROJECT_BRIEF_SELECT = { id: true, name: true, shortCode: true, status: true, endDate: true } as const;
export const RESOURCE_BRIEF_SELECT = { id: true, displayName: true, eid: true, lcrCents: true, chapter: true } as const;
/**
* Explicit select for the resource list endpoint (listStaff).
* Omits large JSONB columns that are unused in all list consumers:
* - availability (~several KB per row, only needed for scheduling calculations)
* - valueScoreBreakdown (JSON, only needed in detail/dashboard views)
* - aiSummary / aiSummaryUpdatedAt / skillMatrixUpdatedAt / portfolioUrl
* This keeps skills and dynamicFields because they are rendered in the resource table.
*/
export const RESOURCE_LIST_SELECT = {
id: true,
eid: true,
displayName: true,
email: true,
chapter: true,
lcrCents: true,
ucrCents: true,
currency: true,
chargeabilityTarget: true,
skills: true,
dynamicFields: true,
blueprintId: true,
isActive: true,
roleId: true,
federalState: true,
valueScore: true,
rolledOff: true,
departed: true,
createdAt: true,
updatedAt: true,
} as const;