fix(external-system-gateway): resolve ExternalSystemGateway-011 — name-keyed repository lookups replace fetch-all-then-filter on the call hot path
This commit is contained in:
@@ -170,8 +170,10 @@ public class DatabaseGateway : IDatabaseGateway
|
||||
string connectionName,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var connections = await _repository.GetAllDatabaseConnectionsAsync(cancellationToken);
|
||||
return connections.FirstOrDefault(c =>
|
||||
c.Name.Equals(connectionName, StringComparison.OrdinalIgnoreCase));
|
||||
// ExternalSystemGateway-011: name-keyed repository lookup instead of
|
||||
// fetch-all-then-filter — connection definitions are resolved on every
|
||||
// cached write / connection request, so the repository performs an indexed
|
||||
// query rather than loading every connection into memory.
|
||||
return await _repository.GetDatabaseConnectionByNameAsync(connectionName, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,13 +373,15 @@ public class ExternalSystemClient : IExternalSystemClient
|
||||
string methodName,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var systems = await _repository.GetAllExternalSystemsAsync(cancellationToken);
|
||||
var system = systems.FirstOrDefault(s => s.Name.Equals(systemName, StringComparison.OrdinalIgnoreCase));
|
||||
// ExternalSystemGateway-011: name-keyed repository lookups instead of
|
||||
// fetch-all-then-filter — definitions are resolved on every hot-path call
|
||||
// (a script's ExternalSystem.Call()), so the repository performs an indexed
|
||||
// query rather than loading every system / every method into memory.
|
||||
var system = await _repository.GetExternalSystemByNameAsync(systemName, cancellationToken);
|
||||
if (system == null)
|
||||
return (null, null);
|
||||
|
||||
var methods = await _repository.GetMethodsByExternalSystemIdAsync(system.Id, cancellationToken);
|
||||
var method = methods.FirstOrDefault(m => m.Name.Equals(methodName, StringComparison.OrdinalIgnoreCase));
|
||||
var method = await _repository.GetMethodByNameAsync(system.Id, methodName, cancellationToken);
|
||||
|
||||
return (system, method);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user