perf(grpc-data): H2 review 6 - Implemented(target) once per node; history serving cached per source
Metadata no longer rebuilds the history view per node x operation (and checks the ACL before the tagname, the ingress order); OriginHistoryPort caches its served-aggregate set per historian source instance.
This commit is contained in:
@@ -88,15 +88,24 @@ public sealed class OriginHistoryPort(OtOpcUaNodeManager nodeManager) : IOriginH
|
||||
{
|
||||
private readonly OtOpcUaNodeManager _nm = nodeManager ?? throw new ArgumentNullException(nameof(nodeManager));
|
||||
|
||||
private (IHistorianDataSource Source, OriginHistoryServing? Serving)? _serving;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <remarks>Cached per historian source instance: the catalog asks per node, so this is a reference compare, not a rebuild.</remarks>
|
||||
public OriginHistoryServing? Serving
|
||||
{
|
||||
get
|
||||
{
|
||||
var source = _nm.HistorianDataSource;
|
||||
if (source is NullHistorianDataSource) return null;
|
||||
var served = AdvertisedAggregateFunctions.ServedBy(source).Select(x => x.ToString()).Order(StringComparer.Ordinal).ToArray();
|
||||
return new OriginHistoryServing(served, Math.Max(1, source.TimestampResolutionTicks));
|
||||
if (_serving is { } cached && ReferenceEquals(cached.Source, source)) return cached.Serving;
|
||||
OriginHistoryServing? serving = null;
|
||||
if (source is not NullHistorianDataSource)
|
||||
{
|
||||
var served = AdvertisedAggregateFunctions.ServedBy(source).Select(x => x.ToString()).Order(StringComparer.Ordinal).ToArray();
|
||||
serving = new OriginHistoryServing(served, Math.Max(1, source.TimestampResolutionTicks));
|
||||
}
|
||||
_serving = (source, serving);
|
||||
return serving;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -207,17 +207,18 @@ public sealed partial class LocalDataServices : IDataConnectionFactory
|
||||
private DataMetadata Metadata(LocalExportCatalog catalog, DataAuthenticatedContext context, DataTarget target, LocalDataNode node)
|
||||
{
|
||||
var operations = DataOperations.None;
|
||||
var implemented = Implemented(target); // once per node (H2 review: no per-operation rebuild of the history view)
|
||||
foreach (var operation in new[] { DataOperations.Browse, DataOperations.Metadata, DataOperations.Read, DataOperations.Write,
|
||||
DataOperations.Subscribe, DataOperations.HistoryRead })
|
||||
if ((node.Supported || operation == DataOperations.Browse)
|
||||
&& (operation != DataOperations.HistoryRead || IsHistorized(node))
|
||||
&& (node.SourceEnabled || operation is DataOperations.Browse or DataOperations.Metadata)
|
||||
&& (Implemented(target) & operation) != 0 && (node.Metadata.AllowedOperations & operation) != 0
|
||||
&& (implemented & operation) != 0 && (node.Metadata.AllowedOperations & operation) != 0
|
||||
&& (operation != DataOperations.Write || node.Metadata.Writable
|
||||
&& string.Equals(_capabilities.Serving.Role, "Primary", StringComparison.OrdinalIgnoreCase))
|
||||
&& Allowed(catalog, context, node, operation)) operations |= operation;
|
||||
&& Allowed(catalog, context, node, operation)
|
||||
&& (operation != DataOperations.HistoryRead || IsHistorized(node))) operations |= operation;
|
||||
// H2: historizing = this caller may HistoryRead it (historized AND granted), so it never separates denied from unhistorized.
|
||||
var history = node.Source is not null && (Implemented(target) & DataOperations.HistoryRead) != 0
|
||||
var history = node.Source is not null && (implemented & DataOperations.HistoryRead) != 0
|
||||
? new DataHistoryInfo(operations.HasFlag(DataOperations.HistoryRead)) : null;
|
||||
return node.Metadata with { AllowedOperations = operations, Writable = node.Metadata.Writable && operations.HasFlag(DataOperations.Write),
|
||||
Serving = catalog.Serving, History = history };
|
||||
|
||||
Reference in New Issue
Block a user