25개 이상의 토픽을 선택하실 수 없습니다.
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- using System.Collections.Concurrent;
-
- namespace Campaign_Tracker.Server.LegacyData.Schema;
-
- /// <summary>
- /// Stores recent compatibility-check results so administrators can view a
- /// history of runs (Story 1.7 AC #5). The default implementation is in-process
- /// and bounded; production deployments can swap a durable store via DI.
- /// </summary>
- public interface ILegacySchemaCheckHistory
- {
- void Record(LegacySchemaCheckResult result);
-
- IReadOnlyList<LegacySchemaCheckResult> GetRecent(int maxCount = 50);
- }
-
- public sealed class InMemoryLegacySchemaCheckHistory : ILegacySchemaCheckHistory
- {
- private const int Capacity = 200;
- private readonly ConcurrentQueue<LegacySchemaCheckResult> _results = new();
- private readonly object _trimLock = new();
-
- public void Record(LegacySchemaCheckResult result)
- {
- ArgumentNullException.ThrowIfNull(result);
- _results.Enqueue(result);
- Trim();
- }
-
- public IReadOnlyList<LegacySchemaCheckResult> GetRecent(int maxCount = 50)
- {
- if (maxCount <= 0) return [];
- return _results.Reverse().Take(maxCount).ToArray();
- }
-
- private void Trim()
- {
- if (_results.Count <= Capacity) return;
- lock (_trimLock)
- {
- while (_results.Count > Capacity && _results.TryDequeue(out _)) { }
- }
- }
- }
|