perf(api): eliminate 3 N+1 query patterns

- timeline-holiday-load-support: deduplicate getResolvedCalendarHolidays
  by location key so resources sharing the same country/state/city resolve
  holidays once instead of per-resource
- rate-card-lookup: add lookupRatesBatch that loads rate card lines once
  and scores locally per demand line, replacing per-line DB round-trips
  in estimate-demand-lines autoFillDemandLineRates
- config-readmodels: include _count in utilization-category list query
  instead of calling getById per category for project counts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-11 22:59:45 +02:00
parent dd2c9c0f88
commit 5a4836d292
8 changed files with 727 additions and 571 deletions
@@ -43,17 +43,9 @@ describe("assistant master data management and utilization read tools", () => {
description: "Client work",
isActive: true,
sortOrder: 1,
_count: { projects: 3 },
},
]),
findUnique: vi.fn().mockResolvedValue({
id: "util_billable",
code: "BILLABLE",
name: "Billable",
description: "Client work",
isActive: true,
sortOrder: 1,
_count: { projects: 3 },
}),
},
};
const ctx = createToolContext(db, {
@@ -71,9 +63,6 @@ describe("assistant master data management and utilization read tools", () => {
expect(db.utilizationCategory.findMany).toHaveBeenCalledWith({
where: {},
orderBy: { sortOrder: "asc" },
});
expect(db.utilizationCategory.findUnique).toHaveBeenCalledWith({
where: { id: "util_billable" },
include: { _count: { select: { projects: true } } },
});