fix: GetTicketSummaries goes from 1 + N queries to 1 + 1
This commit is contained in:
parent
7f902c7271
commit
c21000e658
|
|
@ -2534,9 +2534,26 @@ public class Controller : ControllerBase
|
||||||
if (user is null || user.UserType != 2) return Unauthorized();
|
if (user is null || user.UserType != 2) return Unauthorized();
|
||||||
|
|
||||||
var tickets = Db.GetAllTickets();
|
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<Int64, Installation>()
|
||||||
|
: Db.Installations
|
||||||
|
.Where(i => installationIds.Contains(i.Id))
|
||||||
|
.ToList()
|
||||||
|
.ToDictionary(i => i.Id);
|
||||||
|
|
||||||
var summaries = tickets.Select(t =>
|
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
|
return new
|
||||||
{
|
{
|
||||||
t.Id, t.Subject, t.Status, t.Priority, t.Category, t.SubCategory,
|
t.Id, t.Subject, t.Status, t.Priority, t.Category, t.SubCategory,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue