refactor: consolidate heartbeat findById into single lookup

Merge the route state update and route catalog upsert blocks to share
one registryService.findById() call instead of two, reducing overhead
on the high-frequency heartbeat path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-16 19:04:41 +02:00
parent b77968bb2d
commit 3a54b4d7e7

View File

@@ -257,24 +257,20 @@ public class AgentRegistrationController {
}
}
if (request != null && request.getRouteStates() != null && !request.getRouteStates().isEmpty()) {
if (routeIds != null && !routeIds.isEmpty()) {
AgentInfo agent = registryService.findById(id);
if (agent != null) {
for (var entry : request.getRouteStates().entrySet()) {
RouteStateRegistry.RouteState state = parseRouteState(entry.getValue());
if (state != null) {
routeStateRegistry.setState(agent.applicationId(), entry.getKey(), state);
// Update route states from heartbeat
if (request != null && request.getRouteStates() != null) {
for (var entry : request.getRouteStates().entrySet()) {
RouteStateRegistry.RouteState state = parseRouteState(entry.getValue());
if (state != null) {
routeStateRegistry.setState(agent.applicationId(), entry.getKey(), state);
}
}
}
}
}
// Persist routes in catalog for server-restart recovery
if (routeIds != null && !routeIds.isEmpty()) {
AgentInfo agentForCatalog = registryService.findById(id);
if (agentForCatalog != null) {
String catalogEnv = agentForCatalog.environmentId();
routeCatalogStore.upsert(agentForCatalog.applicationId(), catalogEnv, routeIds);
// Persist routes in catalog for server-restart recovery
routeCatalogStore.upsert(agent.applicationId(), agent.environmentId(), routeIds);
}
}