perf(vendors): look up existing technicians by id in O(1)

The roster reconcile matched each incoming technician with a linear
FirstOrDefault over the existing list, O(n*m). Index the existing list
by id once and use TryGetValue.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
npal 2026-10-05 20:14:51 -05:00
parent 1a1d9d8dcb
commit 49de771fe8

View file

@ -131,6 +131,7 @@ namespace SeaHaven.DataServices.Implementation
var existingTechnicians = await _context.Vendors
.Where(v => v.CompanyId == company.Id && (v.IsDeleted == null || v.IsDeleted == false))
.ToListAsync(cancellationToken);
var existingTechniciansById = existingTechnicians.ToDictionary(v => v.Id);
var snapshotIds = roster.Technicians
.Where(t => t.Id.HasValue)
@ -169,8 +170,7 @@ namespace SeaHaven.DataServices.Implementation
{
if (technician.Id.HasValue)
{
var existing = existingTechnicians.FirstOrDefault(e => e.Id == technician.Id.Value);
if (existing == null)
if (!existingTechniciansById.TryGetValue(technician.Id.Value, out var existing))
continue;
existing.ContactName = technician.ContactName;