refactor(inventory): share retention cap + invariant-culture date format

Introduce InventoryHistoryConfig.RetentionRowsPerViewer as the single
source of truth for the 300-row audit-log cap; InventoryTransaction
aliases it and ItemAcquireHistoryController.Take() references it
directly so the two sites cannot drift. Also adds CultureInfo.InvariantCulture
to the AcquireTime.ToString() call, matching every other WireDateFormat
site in the codebase.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-09 14:55:43 -04:00
parent f9a971a546
commit 37d89aa602
3 changed files with 20 additions and 4 deletions

View File

@@ -0,0 +1,15 @@
namespace SVSim.Database.Services.Inventory;
/// <summary>
/// Shared knobs for the viewer-acquire-history audit log. The write-side prune cap
/// (in <c>InventoryTransaction</c>) and the read-side page size (in
/// <c>ItemAcquireHistoryController</c>) both reference these constants so they cannot drift.
/// </summary>
public static class InventoryHistoryConfig
{
/// <summary>
/// Maximum rows kept per viewer. Older rows are pruned by
/// <c>InventoryTransaction.CommitAsync</c>; the read endpoint pages exactly this many.
/// </summary>
public const int RetentionRowsPerViewer = 300;
}

View File

@@ -9,7 +9,7 @@ namespace SVSim.Database.Services.Inventory;
internal sealed class InventoryTransaction : IInventoryTransaction internal sealed class InventoryTransaction : IInventoryTransaction
{ {
private const int AcquireHistoryRetention = 300; private const int AcquireHistoryRetention = InventoryHistoryConfig.RetentionRowsPerViewer;
private readonly SVSimDbContext _db; private readonly SVSimDbContext _db;
private readonly IDbContextTransaction _dbTx; private readonly IDbContextTransaction _dbTx;

View File

@@ -1,6 +1,8 @@
using System.Globalization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using SVSim.Database; using SVSim.Database;
using SVSim.Database.Services.Inventory;
using SVSim.EmulatedEntrypoint.Models.Dtos.ItemAcquireHistory; using SVSim.EmulatedEntrypoint.Models.Dtos.ItemAcquireHistory;
namespace SVSim.EmulatedEntrypoint.Controllers; namespace SVSim.EmulatedEntrypoint.Controllers;
@@ -9,7 +11,6 @@ namespace SVSim.EmulatedEntrypoint.Controllers;
public sealed class ItemAcquireHistoryController : SVSimController public sealed class ItemAcquireHistoryController : SVSimController
{ {
private const string WireDateFormat = "yyyy-MM-dd HH:mm:ss"; private const string WireDateFormat = "yyyy-MM-dd HH:mm:ss";
private const int PageSize = 300;
private readonly SVSimDbContext _db; private readonly SVSimDbContext _db;
@@ -26,7 +27,7 @@ public sealed class ItemAcquireHistoryController : SVSimController
.Where(h => h.ViewerId == viewerId) .Where(h => h.ViewerId == viewerId)
.OrderByDescending(h => h.AcquireTime) .OrderByDescending(h => h.AcquireTime)
.ThenByDescending(h => h.Id) .ThenByDescending(h => h.Id)
.Take(PageSize) .Take(InventoryHistoryConfig.RetentionRowsPerViewer)
.AsNoTracking() .AsNoTracking()
.ToListAsync(ct); .ToListAsync(ct);
@@ -38,7 +39,7 @@ public sealed class ItemAcquireHistoryController : SVSimController
RewardDetailId = h.RewardDetailId.ToString(), RewardDetailId = h.RewardDetailId.ToString(),
RewardCount = h.RewardCount.ToString(), RewardCount = h.RewardCount.ToString(),
AcquireType = h.AcquireType.ToString(), AcquireType = h.AcquireType.ToString(),
AcquireTime = h.AcquireTime.ToString(WireDateFormat), AcquireTime = h.AcquireTime.ToString(WireDateFormat, CultureInfo.InvariantCulture),
Message = h.Message, Message = h.Message,
}).ToList(), }).ToList(),
}; };