From 3a54b4d7e7e6ab51fcdaaad9d7119235668c40a9 Mon Sep 17 00:00:00 2001 From: hsiegeln <37154749+hsiegeln@users.noreply.github.com> Date: Thu, 16 Apr 2026 19:04:41 +0200 Subject: [PATCH] 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) --- .../AgentRegistrationController.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/cameleer-server-app/src/main/java/com/cameleer/server/app/controller/AgentRegistrationController.java b/cameleer-server-app/src/main/java/com/cameleer/server/app/controller/AgentRegistrationController.java index aed8bea3..30cca8a4 100644 --- a/cameleer-server-app/src/main/java/com/cameleer/server/app/controller/AgentRegistrationController.java +++ b/cameleer-server-app/src/main/java/com/cameleer/server/app/controller/AgentRegistrationController.java @@ -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); } }