Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5091b58

Browse files
committed
fix: Only update workspace LastUsed when the connection payload has changed
This was causing every workspace to update last used to time.Now() whencoderd was restarted!
1 parent29d804e commit5091b58

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

‎coderd/database/databasefake/databasefake.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,30 @@ func (q *fakeQuerier) InsertAgentStat(_ context.Context, p database.InsertAgentS
159159
returnstat,nil
160160
}
161161

162+
func (q*fakeQuerier)GetLatestAgentStat(_ context.Context,agentID uuid.UUID) (database.AgentStat,error) {
163+
q.mutex.RLock()
164+
deferq.mutex.RUnlock()
165+
166+
varlatest*database.AgentStat
167+
for_,agentStat:=rangeq.agentStats {
168+
ifagentStat.AgentID!=agentID {
169+
continue
170+
}
171+
iflatest==nil {
172+
latest=&agentStat
173+
continue
174+
}
175+
ifagentStat.CreatedAt.After(latest.CreatedAt) {
176+
latest=&agentStat
177+
continue
178+
}
179+
}
180+
iflatest==nil {
181+
return database.AgentStat{},sql.ErrNoRows
182+
}
183+
return*latest,nil
184+
}
185+
162186
func (q*fakeQuerier)GetTemplateDAUs(_ context.Context,templateID uuid.UUID) ([]database.GetTemplateDAUsRow,error) {
163187
q.mutex.Lock()
164188
deferq.mutex.Unlock()

‎coderd/database/querier.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries.sql.go

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/agentstats.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ INSERT INTO
1212
VALUES
1313
($1, $2, $3, $4, $5, $6, $7) RETURNING*;
1414

15+
-- name: GetLatestAgentStat :one
16+
SELECT*FROM agent_statsWHERE agent_id= $1ORDER BY created_atDESCLIMIT1;
17+
1518
-- name: GetTemplateDAUs :many
1619
select
1720
(created_at atTIME ZONE'UTC')::dateasdate,

‎coderd/workspaceagents.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,10 +795,22 @@ func (api *API) workspaceAgentReportStats(rw http.ResponseWriter, r *http.Reques
795795
}
796796
deferconn.Close(websocket.StatusAbnormalClosure,"")
797797

798+
varlastReport codersdk.AgentStatsReportResponse
799+
latestStat,err:=api.Database.GetLatestAgentStat(r.Context(),workspaceAgent.ID)
800+
iferr==nil {
801+
err=json.Unmarshal(latestStat.Payload,&lastReport)
802+
iferr!=nil {
803+
httpapi.Write(rw,http.StatusInternalServerError, codersdk.Response{
804+
Message:"Failed to unmarshal stat payload.",
805+
Detail:err.Error(),
806+
})
807+
return
808+
}
809+
}
810+
798811
// Allow overriding the stat interval for debugging and testing purposes.
799812
ctx:=r.Context()
800813
timer:=time.NewTicker(api.AgentStatsRefreshInterval)
801-
varlastReport codersdk.AgentStatsReportResponse
802814
for {
803815
err:=wsjson.Write(ctx,conn, codersdk.AgentStatsReportRequest{})
804816
iferr!=nil {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp