perf(centralui): load template stubs/analysis projections instead of the full tracked graph (review 2026-10-21 07/P-1, 08/P1)
This commit is contained in:
@@ -107,7 +107,7 @@
|
||||
{
|
||||
_siteCount = (await SiteRepository.GetAllSitesAsync()).Count;
|
||||
_dataConnectionCount = (await SiteRepository.GetAllDataConnectionsAsync()).Count;
|
||||
_templateCount = (await TemplateEngineRepository.GetAllTemplatesAsync()).Count;
|
||||
_templateCount = (await TemplateEngineRepository.GetTemplateStubsAsync()).Count;
|
||||
_apiKeyCount = (await ApiKeyAdmin.ListAsync()).Count;
|
||||
}
|
||||
catch
|
||||
|
||||
+1
-1
@@ -267,7 +267,7 @@
|
||||
{
|
||||
try
|
||||
{
|
||||
_templates = (await TemplateEngineRepository.GetAllTemplatesAsync()).ToList();
|
||||
_templates = (await TemplateEngineRepository.GetTemplateStubsAsync()).ToShellTemplates();
|
||||
_folders = (await TemplateEngineRepository.GetAllFoldersAsync()).ToList();
|
||||
_foldersById = _folders.ToDictionary(f => f.Id);
|
||||
if (TemplateId is int tid)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
@page "/design/templates/create"
|
||||
@using ZB.MOM.WW.ScadaBridge.CentralUI.Services
|
||||
@using ZB.MOM.WW.ScadaBridge.Security
|
||||
@using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates
|
||||
@using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories
|
||||
@@ -73,7 +74,7 @@
|
||||
{
|
||||
try
|
||||
{
|
||||
_templates = (await TemplateEngineRepository.GetAllTemplatesAsync()).ToList();
|
||||
_templates = (await TemplateEngineRepository.GetTemplateStubsAsync()).ToShellTemplates();
|
||||
if (ParentId is int pid && _templates.Any(t => t.Id == pid))
|
||||
{
|
||||
_createParentId = pid;
|
||||
|
||||
@@ -125,7 +125,7 @@
|
||||
_loadError = null;
|
||||
try
|
||||
{
|
||||
_templates = (await TemplateEngineRepository.GetAllTemplatesAsync()).ToList();
|
||||
_templates = (await TemplateEngineRepository.GetAllTemplatesForAnalysisAsync()).ToList();
|
||||
|
||||
_selectedTemplate = await TemplateEngineRepository.GetTemplateWithChildrenAsync(Id)
|
||||
?? _templates.FirstOrDefault(t => t.Id == Id);
|
||||
|
||||
@@ -148,7 +148,7 @@
|
||||
_loading = true;
|
||||
try
|
||||
{
|
||||
_templates = (await TemplateEngineRepository.GetAllTemplatesAsync()).ToList();
|
||||
_templates = (await TemplateEngineRepository.GetAllTemplatesForAnalysisAsync()).ToList();
|
||||
_folders = (await TemplateEngineRepository.GetAllFoldersAsync()).ToList();
|
||||
_templatesById = _templates.ToDictionary(t => t.Id);
|
||||
_compositionsById = _templates
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
using ZB.MOM.WW.ScadaBridge.CentralUI.Services;
|
||||
using System.Security.Cryptography;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
@@ -136,7 +137,7 @@ public partial class TransportExport : ComponentBase
|
||||
_errorMessage = null;
|
||||
try
|
||||
{
|
||||
_templates = (await TemplateRepo.GetAllTemplatesAsync()).ToList();
|
||||
_templates = (await TemplateRepo.GetTemplateStubsAsync()).ToShellTemplates();
|
||||
_folders = (await TemplateRepo.GetAllFoldersAsync()).ToList();
|
||||
_sharedScripts = (await TemplateRepo.GetAllSharedScriptsAsync()).ToList();
|
||||
_externalSystems = (await ExternalRepo.GetAllExternalSystemsAsync()).ToList();
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Adapts the untracked, body-free <see cref="TemplateStub"/> projection to childless
|
||||
/// <see cref="Template"/> shells for pickers and trees that only read identity/edge fields
|
||||
/// (id, name, parent, folder, derived flag) — review 2026-10-21 07/P-1.
|
||||
/// </summary>
|
||||
internal static class TemplateStubExtensions
|
||||
{
|
||||
/// <summary>Builds childless <see cref="Template"/> shells carrying only the stub's identity and edges.</summary>
|
||||
/// <param name="stubs">The stubs to adapt.</param>
|
||||
/// <returns>One shell template per stub, in input order.</returns>
|
||||
public static List<Template> ToShellTemplates(this IEnumerable<TemplateStub> stubs) =>
|
||||
stubs.Select(s => new Template(s.Name)
|
||||
{
|
||||
Id = s.Id,
|
||||
ParentTemplateId = s.ParentTemplateId,
|
||||
FolderId = s.FolderId,
|
||||
IsDerived = s.IsDerived,
|
||||
OwnerCompositionId = s.OwnerCompositionId,
|
||||
}).ToList();
|
||||
}
|
||||
+4
-2
@@ -1,3 +1,4 @@
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
using System.Security.Claims;
|
||||
using Bunit;
|
||||
using Bunit.TestDoubles;
|
||||
@@ -108,8 +109,9 @@ public class InstanceCreateTemplateFieldTests : BunitContext
|
||||
new("Elsewhere") { Id = 8, FolderId = 3 },
|
||||
};
|
||||
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(templates));
|
||||
_repo.GetTemplateStubsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateStub>>(
|
||||
(templates).Select(t => new TemplateStub(t.Id, t.Name, t.ParentTemplateId, t.FolderId, t.IsDerived, t.OwnerCompositionId)).ToList()));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateFolder>>(folders));
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ public class TemplateEditInheritedSetTests : BunitContext
|
||||
IsDerived = true,
|
||||
};
|
||||
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(
|
||||
new List<Template> { grandparent, baseTemplate, derived }));
|
||||
_repo.GetTemplateWithChildrenAsync(DerivedId, Arg.Any<CancellationToken>())
|
||||
|
||||
+13
-8
@@ -1,3 +1,4 @@
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
using System.Security.Claims;
|
||||
using Bunit;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -61,8 +62,9 @@ public class TransportExportPageTests : BunitContext
|
||||
|
||||
// Default empty repos so OnInitializedAsync doesn't throw — individual
|
||||
// tests override the bits they care about.
|
||||
_templateRepo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template>()));
|
||||
_templateRepo.GetTemplateStubsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateStub>>(
|
||||
(new List<Template>()).Select(t => new TemplateStub(t.Id, t.Name, t.ParentTemplateId, t.FolderId, t.IsDerived, t.OwnerCompositionId)).ToList()));
|
||||
_templateRepo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateFolder>>(new List<TemplateFolder>()));
|
||||
_templateRepo.GetAllSharedScriptsAsync(Arg.Any<CancellationToken>())
|
||||
@@ -139,8 +141,9 @@ public class TransportExportPageTests : BunitContext
|
||||
// export page no longer offers a keys selection list, only API methods.
|
||||
var apiMethod = new ApiMethod("CreateOrder", "// noop") { Id = 70 };
|
||||
|
||||
_templateRepo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template> { template }));
|
||||
_templateRepo.GetTemplateStubsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateStub>>(
|
||||
(new List<Template> { template }).Select(t => new TemplateStub(t.Id, t.Name, t.ParentTemplateId, t.FolderId, t.IsDerived, t.OwnerCompositionId)).ToList()));
|
||||
_templateRepo.GetAllSharedScriptsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<SharedScript>>(new List<SharedScript> { script }));
|
||||
_externalRepo.GetAllExternalSystemsAsync(Arg.Any<CancellationToken>())
|
||||
@@ -218,8 +221,9 @@ public class TransportExportPageTests : BunitContext
|
||||
});
|
||||
var motor = new Template("Motor") { Id = 2 };
|
||||
|
||||
_templateRepo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template> { pump, motor }));
|
||||
_templateRepo.GetTemplateStubsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateStub>>(
|
||||
(new List<Template> { pump, motor }).Select(t => new TemplateStub(t.Id, t.Name, t.ParentTemplateId, t.FolderId, t.IsDerived, t.OwnerCompositionId)).ToList()));
|
||||
_templateRepo.GetTemplateWithChildrenAsync(1, Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<Template?>(pump));
|
||||
_templateRepo.GetTemplateWithChildrenAsync(2, Arg.Any<CancellationToken>())
|
||||
@@ -262,8 +266,9 @@ public class TransportExportPageTests : BunitContext
|
||||
public async Task Step4_triggers_ExportAsync_with_selected_artifacts_and_user_identity()
|
||||
{
|
||||
var template = new Template("Pump") { Id = 1 };
|
||||
_templateRepo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template> { template }));
|
||||
_templateRepo.GetTemplateStubsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateStub>>(
|
||||
(new List<Template> { template }).Select(t => new TemplateStub(t.Id, t.Name, t.ParentTemplateId, t.FolderId, t.IsDerived, t.OwnerCompositionId)).ToList()));
|
||||
_templateRepo.GetTemplateWithChildrenAsync(1, Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<Template?>(template));
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using System.Security.Claims;
|
||||
using Bunit;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NSubstitute;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Sites;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Security;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
using Dashboard = ZB.MOM.WW.ScadaBridge.CentralUI.Components.Pages.Dashboard;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Pages;
|
||||
|
||||
/// <summary>Review 2026-10-21 07/P-1: the landing page must not load the full tracked template graph just to count.</summary>
|
||||
public class TemplateListLoadTests : BunitContext
|
||||
{
|
||||
/// <summary>The Dashboard counts templates from stubs, never the full graph.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task Dashboard_CountsTemplatesFromStubs_NotFullGraph()
|
||||
{
|
||||
var repo = Substitute.For<ITemplateEngineRepository>();
|
||||
repo.GetTemplateStubsAsync(Arg.Any<CancellationToken>()).Returns(Task.FromResult<IReadOnlyList<TemplateStub>>(
|
||||
new List<TemplateStub> { new(1, "A", null, null, false, null), new(2, "B", null, null, false, null) }));
|
||||
var sites = Substitute.For<ISiteRepository>();
|
||||
sites.GetAllSitesAsync().Returns(new List<Site>());
|
||||
sites.GetAllDataConnectionsAsync().Returns(new List<DataConnection>());
|
||||
var keys = Substitute.For<IInboundApiKeyAdmin>();
|
||||
Services.AddSingleton(repo);
|
||||
Services.AddSingleton(sites);
|
||||
Services.AddSingleton(keys);
|
||||
Services.AddSingleton(Substitute.For<AuthenticationStateProvider>());
|
||||
AddAuthorization();
|
||||
|
||||
var cut = Render<Dashboard>();
|
||||
await cut.WaitForStateAsync(() => cut.Markup.Contains("Templates"));
|
||||
|
||||
await repo.Received(1).GetTemplateStubsAsync(Arg.Any<CancellationToken>());
|
||||
await repo.DidNotReceive().GetAllTemplatesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class TemplatesPageTests : BunitContext
|
||||
[Fact]
|
||||
public void Renders_EmptyState_WhenNoTemplatesOrFolders()
|
||||
{
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template>()));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateFolder>>(new List<TemplateFolder>()));
|
||||
@@ -85,7 +85,7 @@ public class TemplatesPageTests : BunitContext
|
||||
{
|
||||
var folder = new TemplateFolder("Dev") { Id = 1 };
|
||||
var template = new Template("TestMachine") { Id = 5, FolderId = 1 };
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template> { template }));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateFolder>>(new List<TemplateFolder> { folder }));
|
||||
@@ -114,7 +114,7 @@ public class TemplatesPageTests : BunitContext
|
||||
new TemplateComposition("DelmiaReceiver") { Id = 10, ComposedTemplateId = 99 });
|
||||
var composed = new Template("Other") { Id = 99 };
|
||||
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template> { template, composed }));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateFolder>>(new List<TemplateFolder>()));
|
||||
@@ -153,7 +153,7 @@ public class TemplatesPageTests : BunitContext
|
||||
cvdReactor.Compositions.Add(
|
||||
new TemplateComposition("LeftReactorSide") { Id = 200, TemplateId = 1, ComposedTemplateId = 8 });
|
||||
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(
|
||||
new List<Template> { cvdReactor, reactorSide, leftReactorSide, leakTest }));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
@@ -191,7 +191,7 @@ public class TemplatesPageTests : BunitContext
|
||||
var alpha = new Template("AlphaDevice") { Id = 10, FolderId = 1 };
|
||||
var beta = new Template("BetaDevice") { Id = 20, FolderId = 1 };
|
||||
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template> { alpha, beta }));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateFolder>>(new List<TemplateFolder> { folder }));
|
||||
@@ -243,7 +243,7 @@ public class TemplatesPageTests : BunitContext
|
||||
var beta = new TemplateFolder("Beta") { Id = 2, ParentFolderId = null, SortOrder = 1 };
|
||||
var all = new List<TemplateFolder> { alpha, beta };
|
||||
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template>()));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(_ => Task.FromResult<IReadOnlyList<TemplateFolder>>(all));
|
||||
@@ -307,7 +307,7 @@ public class TemplatesPageTests : BunitContext
|
||||
// Tree reloaded after the mutation: LoadTemplatesAsync re-fetched (initial
|
||||
// load + post-reorder reload). GetAllTemplatesAsync is only touched by the
|
||||
// page's load path, never by ReorderFolderAsync, so 2 calls == one reload.
|
||||
_repo.Received(2).GetAllTemplatesAsync(Arg.Any<CancellationToken>());
|
||||
_repo.Received(2).GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that choosing move up dispatches a reorder up and reloads the tree.</summary>
|
||||
@@ -333,7 +333,7 @@ public class TemplatesPageTests : BunitContext
|
||||
Assert.Equal(1, alpha.SortOrder);
|
||||
|
||||
// Tree reloaded after the mutation (one reload == GetAllTemplatesAsync twice).
|
||||
_repo.Received(2).GetAllTemplatesAsync(Arg.Any<CancellationToken>());
|
||||
_repo.Received(2).GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that move up is disabled for the first sibling folder.</summary>
|
||||
@@ -372,7 +372,7 @@ public class TemplatesPageTests : BunitContext
|
||||
[Fact]
|
||||
public void RootContextMenu_OffersNewFolderAndNewTemplate()
|
||||
{
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template>()));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateFolder>>(new List<TemplateFolder>()));
|
||||
@@ -392,7 +392,7 @@ public class TemplatesPageTests : BunitContext
|
||||
[Fact]
|
||||
public void RootContextMenu_NewTemplate_NavigatesToRootCreate()
|
||||
{
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template>()));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateFolder>>(new List<TemplateFolder>()));
|
||||
@@ -417,7 +417,7 @@ public class TemplatesPageTests : BunitContext
|
||||
|
||||
private void SeedOneTemplate(int id, string name)
|
||||
{
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template> { new(name) { Id = id } }));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateFolder>>(new List<TemplateFolder>()));
|
||||
|
||||
Reference in New Issue
Block a user