Review 1.3: the overview works before the agent has migrated to 0016

GetInstancesAsync now reads insight.ConfiguredInstances only when it exists, so a
1.3 web UI (e.g. upgraded first on its own server) still shows the overview
against a repository a 1.2 agent has not migrated yet.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Søren Eggert Lundsteen Olsen 2026-10-02 13:07:32 +02:00
parent a66e3f2b3b
commit f0c5d01294

View file

@ -93,18 +93,24 @@ public sealed partial class InsightRepository
public async Task<IReadOnlyList<InstanceOverview>> GetInstancesAsync(CancellationToken cancellationToken = default)
{
await using var connection = await OpenAsync(cancellationToken).ConfigureAwait(false);
// 1.3: paused or removed in Servere og databaser. A name without any configuration row (history from before 1.3)
// counts as monitored, as it did. Guarded, so a 1.3 web UI still shows the overview against a repository the
// agent has not migrated yet (e.g. the web upgraded first on its own server).
var rows = await connection.QueryAsync<InstanceOverview>("""
DECLARE @configured TABLE (Name nvarchar(128) NOT NULL PRIMARY KEY, Configured int NOT NULL, Active int NOT NULL, Paused int NOT NULL);
IF OBJECT_ID(N'insight.ConfiguredInstances') IS NOT NULL
INSERT @configured (Name, Configured, Active, Paused)
SELECT Name, COUNT(*), MAX(CASE WHEN RemovedAt IS NULL THEN 1 ELSE 0 END), MAX(CASE WHEN RemovedAt IS NULL AND Paused = 1 THEN 1 ELSE 0 END)
FROM insight.ConfiguredInstances
GROUP BY Name;
SELECT i.InstanceId, i.Name, i.ServerName, i.ProductVersion, i.ProductLevel, i.ProductUpdateLevel, i.Edition, i.EngineEdition, i.ConnectionProvider,
i.UsedLegacyFallback, i.LastSeenAt, i.LastErrorAt, i.LastError,
ISNULL(f.Critical, 0) AS Critical, ISNULL(f.High, 0) AS High, ISNULL(f.Medium, 0) AS Medium, ISNULL(f.Low, 0) AS Low, ISNULL(f.Info, 0) AS Info,
ISNULL(r.NotMeasurable, 0) AS NotMeasurable, ISNULL(r.ManualChecks, 0) AS ManualChecks,
CAST(ISNULL(c.Paused, 0) AS bit) AS Paused, CAST(CASE WHEN c.Configured > 0 AND c.Active = 0 THEN 1 ELSE 0 END AS bit) AS Removed
FROM insight.Instances i
/* 1.3: paused or removed in Servere og databaser. A name without any configuration row (history from before
1.3) counts as monitored, as it did. */
OUTER APPLY (SELECT COUNT(*) AS Configured, MAX(CASE WHEN RemovedAt IS NULL THEN 1 ELSE 0 END) AS Active,
MAX(CASE WHEN RemovedAt IS NULL AND Paused = 1 THEN 1 ELSE 0 END) AS Paused
FROM insight.ConfiguredInstances WHERE Name = i.Name) c
LEFT JOIN @configured c ON c.Name = i.Name
OUTER APPLY (SELECT SUM(CASE WHEN Severity = 4 THEN 1 ELSE 0 END) AS Critical, SUM(CASE WHEN Severity = 3 THEN 1 ELSE 0 END) AS High,
SUM(CASE WHEN Severity = 2 THEN 1 ELSE 0 END) AS Medium, SUM(CASE WHEN Severity = 1 THEN 1 ELSE 0 END) AS Low,
SUM(CASE WHEN Severity = 0 THEN 1 ELSE 0 END) AS Info