From c21000e6589d3fa6649000ff19c5da7f0e0e249c Mon Sep 17 00:00:00 2001 From: Yinyin Liu Date: Wed, 29 Apr 2026 15:13:08 +0200 Subject: [PATCH] fix: GetTicketSummaries goes from 1 + N queries to 1 + 1 --- csharp/App/Backend/Controller.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/csharp/App/Backend/Controller.cs b/csharp/App/Backend/Controller.cs index 6c4f5bee3..4d23b77ef 100644 --- a/csharp/App/Backend/Controller.cs +++ b/csharp/App/Backend/Controller.cs @@ -2534,9 +2534,26 @@ public class Controller : ControllerBase if (user is null || user.UserType != 2) return Unauthorized(); var tickets = Db.GetAllTickets(); + + var installationIds = tickets + .Where(t => t.InstallationId.HasValue) + .Select(t => t.InstallationId!.Value) + .Distinct() + .ToList(); + + var installationsById = installationIds.Count == 0 + ? new Dictionary() + : Db.Installations + .Where(i => installationIds.Contains(i.Id)) + .ToList() + .ToDictionary(i => i.Id); + var summaries = tickets.Select(t => { - var installation = t.InstallationId.HasValue ? Db.GetInstallationById(t.InstallationId.Value) : null; + Installation? installation = null; + if (t.InstallationId.HasValue) + installationsById.TryGetValue(t.InstallationId.Value, out installation); + return new { t.Id, t.Subject, t.Status, t.Priority, t.Category, t.SubCategory,