You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf(agentapi): cache agent ID and Name to reduce database queries
Previously, MetadataAPI, AppsAPI, StatsAPI, and ConnectionLogAPI called
GetWorkspaceAgentByID on every request to retrieve the agent ID and Name.
For deployments with 1000+ agents, this resulted in 4000+ queries/second.
This change introduces agent field caching to eliminate these redundant
database queries. Since agent ID and Name are static fields that never
change during an agent connection lifetime, we can safely cache them
when the agent API is initialized.
Changes:
- Add CachedAgentFields struct with thread-safe ID and Name getters
- Update agentapi.New() to accept agent parameter and initialize cache
- Modify MetadataAPI, AppsAPI, StatsAPI, and ConnectionLogAPI to use
cached fields instead of calling AgentFn
- Update all test files to initialize agent cache properly
- Add fallback to AgentFn if cache is not populated (safety)
This reduces database query load by ~4000 queries/second for
deployments with 1000 agents, while maintaining backward compatibility
with existing code paths.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
0 commit comments