fix: limit calls to GetWorkspaceAgentByID in agentapi (#23015)

We currently call GetWorkspaceAgentByID millions of times at scale
unnecessarily. This PR embeds immutable fields into the relevant
services instead of fetching for them every time.

resolves https://github.com/coder/scaletest/issues/84

Confirmed with a 10k scaletest that this changeset takes the query from
10M+ queries down to 39k
This commit is contained in:
Jon Ayers
2026-03-20 15:42:05 -05:00
committed by GitHub
parent 32021b3ac2
commit f135ffdb3a
23 changed files with 173 additions and 228 deletions
+3 -9
View File
@@ -80,9 +80,7 @@ func TestBatchUpdateMetadata(t *testing.T) {
t.Cleanup(batcher.Close)
api := &agentapi.MetadataAPI{
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
return agent, nil
},
AgentID: agent.ID,
Workspace: &agentapi.CachedWorkspaceFields{},
Log: testutil.Logger(t),
Batcher: batcher,
@@ -159,9 +157,7 @@ func TestBatchUpdateMetadata(t *testing.T) {
t.Cleanup(batcher.Close)
api := &agentapi.MetadataAPI{
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
return agent, nil
},
AgentID: agent.ID,
Workspace: &agentapi.CachedWorkspaceFields{},
Log: testutil.Logger(t),
Batcher: batcher,
@@ -241,9 +237,7 @@ func TestBatchUpdateMetadata(t *testing.T) {
t.Cleanup(batcher.Close)
api := &agentapi.MetadataAPI{
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
return agent, nil
},
AgentID: agent.ID,
Workspace: &agentapi.CachedWorkspaceFields{},
Log: testutil.Logger(t),
Batcher: batcher,