Files
lmxopcua/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Queries/DeploymentQueries.cs
T
Joseph Doherty ea976ffa81 fix(perf): #996 Wave 4 — blob-free health probes, narrow data-connections load, off-thread coordinator acks + AdminOps audit, events page cap, capped reservations page
C-6: DeploymentQueries projects Deployment without ArtifactBlob (DbHealthProbe, readiness, ClusterOverview, DriverHost boot).
C-11/A-5: DraftSnapshotFactory.FromConfigDbForDataConnectionsAsync + one-parse-per-artifact LoadAppliedAsync + capped pickers.
H-6: ConfigPublishCoordinator persists acks off the actor thread (AckPersisted); deadline backlog kicked in parallel.
H-3: Restart/Reconnect reply = dispatch; ConfigEdit audit written off-mailbox, failure logged not surfaced.
U-6: ServerHistorian:MaxEventsPerRead (default 10000) pages HistoryReadEvents; advertised as MaxReturnEventValues.
A-8: /reservations active-only by default, projected, capped at 200.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-12-03 10:58:50 -05:00

57 lines
2.8 KiB
C#

using Microsoft.EntityFrameworkCore;
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;
namespace ZB.MOM.WW.OtOpcUa.Configuration.Queries;
/// <summary>
/// A <see cref="Deployment"/> row WITHOUT its <c>ArtifactBlob</c> (lmxopcua#996, review C-6). The blob is the
/// gzip of the whole fleet config (hundreds of KB to MBs); every reader that only needs the row's metadata
/// must project to this shape instead of materialising the entity.
/// </summary>
/// <param name="DeploymentId">Deployment id.</param>
/// <param name="RevisionHash">Artifact revision hash.</param>
/// <param name="Status">Deployment status.</param>
/// <param name="CreatedBy">Creator.</param>
/// <param name="CreatedAtUtc">Creation time.</param>
/// <param name="SealedAtUtc">Seal time, when sealed.</param>
/// <param name="FailureReason">Failure text, when failed.</param>
public sealed record DeploymentSummary(
Guid DeploymentId,
string RevisionHash,
DeploymentStatus Status,
string CreatedBy,
DateTime CreatedAtUtc,
DateTime? SealedAtUtc,
string? FailureReason);
/// <summary>
/// Blob-free <c>Deployment</c> queries shared by the DB health probe, the readiness check, the cluster overview
/// and the driver-host boot read. A plain <c>db.Deployments…ToList()</c> drags <c>ArtifactBlob</c> over the wire;
/// these projections cannot.
/// </summary>
public static class DeploymentQueries
{
/// <summary>
/// Liveness probe query: selects one <c>DeploymentId</c> (never the artifact blob). Used by the 5 s
/// <c>DbHealthProbeActor</c> tick and the <c>configdb</c> readiness check.
/// </summary>
/// <param name="db">The config database context.</param>
/// <returns>A query yielding at most one deployment id.</returns>
public static IQueryable<Guid> ProbeQuery(OtOpcUaConfigDbContext db) =>
db.Deployments.AsNoTracking().Select(d => d.DeploymentId).Take(1);
/// <summary>Projects a deployment query to <see cref="DeploymentSummary"/> (no blob).</summary>
/// <param name="deployments">The source query.</param>
/// <returns>The blob-free projection.</returns>
public static IQueryable<DeploymentSummary> ToSummary(this IQueryable<Deployment> deployments) =>
deployments.Select(d => new DeploymentSummary(
d.DeploymentId, d.RevisionHash, d.Status, d.CreatedBy, d.CreatedAtUtc, d.SealedAtUtc, d.FailureReason));
/// <summary>The newest deployment (by <c>CreatedAtUtc</c>) as a blob-free summary.</summary>
/// <param name="db">The config database context.</param>
/// <returns>A query yielding at most one summary.</returns>
public static IQueryable<DeploymentSummary> LatestSummary(OtOpcUaConfigDbContext db) =>
db.Deployments.AsNoTracking().OrderByDescending(d => d.CreatedAtUtc).ToSummary().Take(1);
}