No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

45 líneas
1.3KB

  1. using System.Collections.Concurrent;
  2. namespace Campaign_Tracker.Server.LegacyData.Schema;
  3. /// <summary>
  4. /// Stores recent compatibility-check results so administrators can view a
  5. /// history of runs (Story 1.7 AC #5). The default implementation is in-process
  6. /// and bounded; production deployments can swap a durable store via DI.
  7. /// </summary>
  8. public interface ILegacySchemaCheckHistory
  9. {
  10. void Record(LegacySchemaCheckResult result);
  11. IReadOnlyList<LegacySchemaCheckResult> GetRecent(int maxCount = 50);
  12. }
  13. public sealed class InMemoryLegacySchemaCheckHistory : ILegacySchemaCheckHistory
  14. {
  15. private const int Capacity = 200;
  16. private readonly ConcurrentQueue<LegacySchemaCheckResult> _results = new();
  17. private readonly object _trimLock = new();
  18. public void Record(LegacySchemaCheckResult result)
  19. {
  20. ArgumentNullException.ThrowIfNull(result);
  21. _results.Enqueue(result);
  22. Trim();
  23. }
  24. public IReadOnlyList<LegacySchemaCheckResult> GetRecent(int maxCount = 50)
  25. {
  26. if (maxCount <= 0) return [];
  27. return _results.Reverse().Take(maxCount).ToArray();
  28. }
  29. private void Trim()
  30. {
  31. if (_results.Count <= Capacity) return;
  32. lock (_trimLock)
  33. {
  34. while (_results.Count > Capacity && _results.TryDequeue(out _)) { }
  35. }
  36. }
  37. }

Powered by TurnKey Linux.