using ZB.MOM.WW.ScadaBridge.Commons.Messages.Audit; using ZB.MOM.WW.ScadaBridge.Commons.Messages.Notification; using ZB.MOM.WW.ScadaBridge.Commons.Types; namespace ZB.MOM.WW.ScadaBridge.CentralUI.Services; /// /// Process-level memoized point-in-time KPI snapshots shared by every Blazor circuit on /// this node (the per-circuit polling half). /// /// Every KPI here is a global, point-in-time aggregate: it does not vary by user, /// site scope, or role, so N circuits asking for it inside one refresh window are asking /// the identical question. Without memoization, ten Health dashboards meant ten Asks → /// ten aggregate SQL round trips every ten seconds. Each accessor is independently /// memoized with a short TTL and single-flight production, so the fleet costs ONE round /// trip per KPI per window regardless of viewer count. /// /// /// Faults are never memoized: a failed query is re-attempted by the next caller, and the /// caller still sees the exception exactly as it would from a direct query — the pages' /// existing per-tile "unavailable" degradation is unchanged. /// /// public interface IKpiSnapshotCache { /// Global Notification Outbox KPIs (queue depth, stuck, parked, delivered-last-interval). /// Bypass a still-fresh value (operator "Refresh"); an in-flight round is still joined. /// Cancels this caller's wait, never the shared flight. /// The memoized notification KPI response. Task GetNotificationKpisAsync( bool forceRefresh = false, CancellationToken cancellationToken = default); /// Per-source-site Notification Outbox KPI breakdown. /// Bypass a still-fresh value; an in-flight round is still joined. /// Cancels this caller's wait, never the shared flight. /// The memoized per-site notification KPI response. Task GetPerSiteNotificationKpisAsync( bool forceRefresh = false, CancellationToken cancellationToken = default); /// Per-node Notification Outbox KPI breakdown (grouped by SourceNode). /// Bypass a still-fresh value; an in-flight round is still joined. /// Cancels this caller's wait, never the shared flight. /// The memoized per-node notification KPI response. Task GetPerNodeNotificationKpisAsync( bool forceRefresh = false, CancellationToken cancellationToken = default); /// Global Site Call Audit KPIs (buffered, stuck, parked). /// Bypass a still-fresh value; an in-flight round is still joined. /// Cancels this caller's wait, never the shared flight. /// The memoized site call KPI response. Task GetSiteCallKpisAsync( bool forceRefresh = false, CancellationToken cancellationToken = default); /// Per-node Site Call Audit KPI breakdown (grouped by SourceNode). /// Bypass a still-fresh value; an in-flight round is still joined. /// Cancels this caller's wait, never the shared flight. /// The memoized per-node site call KPI response. Task GetPerNodeSiteCallKpisAsync( bool forceRefresh = false, CancellationToken cancellationToken = default); /// /// Audit Log KPI snapshot (1h volume + error rate over the central AuditLog table, /// plus the summed per-site backlog). /// /// Bypass a still-fresh value; an in-flight round is still joined. /// Cancels this caller's wait, never the shared flight. /// The memoized audit KPI snapshot. Task GetAuditKpiSnapshotAsync( bool forceRefresh = false, CancellationToken cancellationToken = default); }