mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: Only update workspace LastUsed when the connection payload has changed (#4115)
This was causing every workspace to update last used to time.Now() when coderd was restarted!
This commit is contained in:
@@ -795,10 +795,22 @@ func (api *API) workspaceAgentReportStats(rw http.ResponseWriter, r *http.Reques
|
||||
}
|
||||
defer conn.Close(websocket.StatusAbnormalClosure, "")
|
||||
|
||||
var lastReport codersdk.AgentStatsReportResponse
|
||||
latestStat, err := api.Database.GetLatestAgentStat(r.Context(), workspaceAgent.ID)
|
||||
if err == nil {
|
||||
err = json.Unmarshal(latestStat.Payload, &lastReport)
|
||||
if err != nil {
|
||||
httpapi.Write(rw, http.StatusInternalServerError, codersdk.Response{
|
||||
Message: "Failed to unmarshal stat payload.",
|
||||
Detail: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Allow overriding the stat interval for debugging and testing purposes.
|
||||
ctx := r.Context()
|
||||
timer := time.NewTicker(api.AgentStatsRefreshInterval)
|
||||
var lastReport codersdk.AgentStatsReportResponse
|
||||
for {
|
||||
err := wsjson.Write(ctx, conn, codersdk.AgentStatsReportRequest{})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user