feat(replay): add BattleHistoryWriter with 50-row per-viewer retention

Idempotent on (ViewerId, BattleId); evicts oldest CreateTime row when
at cap. No-op when ctx is null (server-restart safety).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-10 07:43:50 -04:00
parent 869f9ce13d
commit 2b6c7bd6a4
4 changed files with 188 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ using SVSim.Database.Repositories.Story;
using SVSim.Database.Repositories.Viewer;
using SVSim.Database.Services;
using SVSim.Database.Services.Friend;
using SVSim.Database.Services.Replay;
using SVSim.EmulatedEntrypoint.Configuration;
using SVSim.EmulatedEntrypoint.Extensions;
using SVSim.EmulatedEntrypoint.Matching;
@@ -116,6 +117,9 @@ public class Program
builder.Services.AddScoped<IFriendService, FriendService>();
builder.Services.AddScoped<IPlayedTogetherWriter, FriendService>();
builder.Services.AddSingleton<IBattleContextStore, InMemoryBattleContextStore>();
builder.Services.AddScoped<IBattleHistoryWriter, BattleHistoryWriter>();
// Deck-code mint/resolve uses IMemoryCache for ephemeral (3-min TTL) storage; no DB
// row, no migration. Singleton because the cache + RNG seam are process-wide.
builder.Services.AddMemoryCache();