almost ready
This commit is contained in:
@@ -23,6 +23,8 @@ public class SkinTrackerDbContext : DbContext
|
||||
public DbSet<Collection> Collections => Set<Collection>();
|
||||
public DbSet<Skin> Skins => Set<Skin>();
|
||||
public DbSet<SkinCondition> SkinConditions => Set<SkinCondition>();
|
||||
public DbSet<SkinSweep> SkinSweeps => Set<SkinSweep>();
|
||||
public DbSet<SkinConditionSweep> SkinConditionSweeps => Set<SkinConditionSweep>();
|
||||
public DbSet<SteamUser> SteamUsers => Set<SteamUser>();
|
||||
public DbSet<SkinInstance> SkinInstances => Set<SkinInstance>();
|
||||
public DbSet<InventoryItem> InventoryItems => Set<InventoryItem>();
|
||||
@@ -31,6 +33,7 @@ public class SkinTrackerDbContext : DbContext
|
||||
public DbSet<PriceHistory> PriceHistories => Set<PriceHistory>();
|
||||
public DbSet<Listing> Listings => Set<Listing>();
|
||||
public DbSet<CsMoneyListing> CsMoneyListings => Set<CsMoneyListing>();
|
||||
public DbSet<SkinLandListing> SkinLandListings => Set<SkinLandListing>();
|
||||
|
||||
/// <summary>Read-only cross-market view UNIONing the per-market listing tables.</summary>
|
||||
public DbSet<MarketListing> MarketListings => Set<MarketListing>();
|
||||
@@ -47,6 +50,8 @@ public class SkinTrackerDbContext : DbContext
|
||||
modelBuilder.ApplyConfiguration(new CollectionConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new SkinConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new SkinConditionConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new SkinSweepConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new SkinConditionSweepConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new SteamUserConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new SkinInstanceConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new InventoryItemConfiguration());
|
||||
@@ -55,6 +60,7 @@ public class SkinTrackerDbContext : DbContext
|
||||
modelBuilder.ApplyConfiguration(new PriceHistoryConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new ListingConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new CsMoneyListingConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new SkinLandListingConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new MarketListingConfiguration());
|
||||
}
|
||||
}
|
||||
|
||||
64
BlueLaminate/BlueLaminate.EFCore/Data/SweepCheckpoints.cs
Normal file
64
BlueLaminate/BlueLaminate.EFCore/Data/SweepCheckpoints.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using BlueLaminate.EFCore.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BlueLaminate.EFCore.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Write helpers for the per-site sweep checkpoints (<see cref="SkinSweep"/> /
|
||||
/// <see cref="SkinConditionSweep"/>). Each marketplace sweeper stamps its own row
|
||||
/// keyed by <c>(entity, source)</c>, so a band swept on one site is still "never
|
||||
/// swept" on another. Adding a new site means a new <see cref="SweepSource"/>
|
||||
/// constant — no schema changes.
|
||||
/// <para>
|
||||
/// Reads stay inline in the sweep queries (a correlated subquery over the navigation
|
||||
/// for the relevant <c>Source</c>) so EF can translate and order by them server-side.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static class SweepCheckpoints
|
||||
{
|
||||
/// <summary>
|
||||
/// Record that <paramref name="source"/> just swept this wear band. Upserts the
|
||||
/// single (condition, source) row via the change tracker; the caller persists with
|
||||
/// <see cref="DbContext.SaveChangesAsync"/>.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>As <see cref="StampConditionAsync"/>, for a whole-skin unit (no wear bands).</summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user