mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-06 08:52:09 +00:00
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:
parent
1a1d9d8dcb
commit
49de771fe8
1 changed files with 2 additions and 2 deletions
|
|
@ -131,6 +131,7 @@ namespace SeaHaven.DataServices.Implementation
|
||||||
var existingTechnicians = await _context.Vendors
|
var existingTechnicians = await _context.Vendors
|
||||||
.Where(v => v.CompanyId == company.Id && (v.IsDeleted == null || v.IsDeleted == false))
|
.Where(v => v.CompanyId == company.Id && (v.IsDeleted == null || v.IsDeleted == false))
|
||||||
.ToListAsync(cancellationToken);
|
.ToListAsync(cancellationToken);
|
||||||
|
var existingTechniciansById = existingTechnicians.ToDictionary(v => v.Id);
|
||||||
|
|
||||||
var snapshotIds = roster.Technicians
|
var snapshotIds = roster.Technicians
|
||||||
.Where(t => t.Id.HasValue)
|
.Where(t => t.Id.HasValue)
|
||||||
|
|
@ -169,8 +170,7 @@ namespace SeaHaven.DataServices.Implementation
|
||||||
{
|
{
|
||||||
if (technician.Id.HasValue)
|
if (technician.Id.HasValue)
|
||||||
{
|
{
|
||||||
var existing = existingTechnicians.FirstOrDefault(e => e.Id == technician.Id.Value);
|
if (!existingTechniciansById.TryGetValue(technician.Id.Value, out var existing))
|
||||||
if (existing == null)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
existing.ContactName = technician.ContactName;
|
existing.ContactName = technician.ContactName;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue