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:
Kyle Carberry
2022-09-19 14:11:18 -05:00
committed by GitHub
parent 153e96f574
commit 72d6731924
5 changed files with 63 additions and 1 deletions

View File

@ -24,6 +24,25 @@ func (q *sqlQuerier) DeleteOldAgentStats(ctx context.Context) error {
return err
}
const getLatestAgentStat = `-- name: GetLatestAgentStat :one
SELECT id, created_at, user_id, agent_id, workspace_id, template_id, payload FROM agent_stats WHERE agent_id = $1 ORDER BY created_at DESC LIMIT 1
`
func (q *sqlQuerier) GetLatestAgentStat(ctx context.Context, agentID uuid.UUID) (AgentStat, error) {
row := q.db.QueryRowContext(ctx, getLatestAgentStat, agentID)
var i AgentStat
err := row.Scan(
&i.ID,
&i.CreatedAt,
&i.UserID,
&i.AgentID,
&i.WorkspaceID,
&i.TemplateID,
&i.Payload,
)
return i, err
}
const getTemplateDAUs = `-- name: GetTemplateDAUs :many
select
(created_at at TIME ZONE 'UTC')::date as date,