using BlueLaminate.EFCore.Entities; using Microsoft.EntityFrameworkCore; namespace BlueLaminate.EFCore.Data; /// /// Write helpers for the per-site sweep checkpoints ( / /// ). Each marketplace sweeper stamps its own row /// keyed by (entity, source), so a band swept on one site is still "never /// swept" on another. Adding a new site means a new /// constant — no schema changes. /// /// Reads stay inline in the sweep queries (a correlated subquery over the navigation /// for the relevant Source) so EF can translate and order by them server-side. /// /// public static class SweepCheckpoints { /// /// Record that just swept this wear band. Upserts the /// single (condition, source) row via the change tracker; the caller persists with /// . /// public static async Task StampConditionAsync( SkinTrackerDbContext db, int conditionId, string source, DateTimeOffset sweptAt, CancellationToken ct) { var existing = await db.SkinConditionSweeps .FirstOrDefaultAsync(s => s.SkinConditionId == conditionId && s.Source == source, ct); if (existing is null) { db.SkinConditionSweeps.Add(new SkinConditionSweep { SkinConditionId = conditionId, Source = source, SweptAt = sweptAt, }); } else { existing.SweptAt = sweptAt; } } /// As , for a whole-skin unit (no wear bands). public static async Task StampSkinAsync( SkinTrackerDbContext db, int skinId, string source, DateTimeOffset sweptAt, CancellationToken ct) { var existing = await db.SkinSweeps .FirstOrDefaultAsync(s => s.SkinId == skinId && s.Source == source, ct); if (existing is null) { db.SkinSweeps.Add(new SkinSweep { SkinId = skinId, Source = source, SweptAt = sweptAt, }); } else { existing.SweptAt = sweptAt; } } }