mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: return only the first workspace agent script timing per script (#16203)
Fixes https://github.com/coder/coder/issues/16124 If a workspace agent crashes, it is possible for any startup scripts to be ran again. This PR makes it so that the `GetWorkspaceAgentScriptTimingsByBuildID` query only returns the first timing recorded per-script.
This commit is contained in:
@@ -6388,6 +6388,15 @@ func (q *FakeQuerier) GetWorkspaceAgentScriptTimingsByBuildID(ctx context.Contex
|
||||
WorkspaceAgentName: agent.Name,
|
||||
})
|
||||
}
|
||||
|
||||
// We want to only return the first script run for each Script ID.
|
||||
slices.SortFunc(rows, func(a, b database.GetWorkspaceAgentScriptTimingsByBuildIDRow) int {
|
||||
return a.StartedAt.Compare(b.StartedAt)
|
||||
})
|
||||
rows = slices.CompactFunc(rows, func(e1, e2 database.GetWorkspaceAgentScriptTimingsByBuildIDRow) bool {
|
||||
return e1.ScriptID == e2.ScriptID
|
||||
})
|
||||
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user