mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
feat: add last_used search params to workspaces (#9230)
* feat: add last_used search params to workspaces
This commit is contained in:
@ -6064,6 +6064,18 @@ func (q *FakeQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg database.
|
||||
continue
|
||||
}
|
||||
|
||||
if !arg.LastUsedBefore.IsZero() {
|
||||
if workspace.LastUsedAt.After(arg.LastUsedBefore) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if !arg.LastUsedAfter.IsZero() {
|
||||
if workspace.LastUsedAt.Before(arg.LastUsedAfter) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if arg.Status != "" {
|
||||
build, err := q.getLatestWorkspaceBuildByWorkspaceIDNoLock(ctx, workspace.ID)
|
||||
if err != nil {
|
||||
|
@ -317,8 +317,9 @@ func ProvisionerJob(t testing.TB, db database.Store, orig database.ProvisionerJo
|
||||
// Make sure when we acquire the job, we only get this one.
|
||||
orig.Tags[id.String()] = "true"
|
||||
}
|
||||
jobID := takeFirst(orig.ID, uuid.New())
|
||||
job, err := db.InsertProvisionerJob(genCtx, database.InsertProvisionerJobParams{
|
||||
ID: takeFirst(orig.ID, uuid.New()),
|
||||
ID: jobID,
|
||||
CreatedAt: takeFirst(orig.CreatedAt, database.Now()),
|
||||
UpdatedAt: takeFirst(orig.UpdatedAt, database.Now()),
|
||||
OrganizationID: takeFirst(orig.OrganizationID, uuid.New()),
|
||||
@ -343,7 +344,7 @@ func ProvisionerJob(t testing.TB, db database.Store, orig database.ProvisionerJo
|
||||
|
||||
if !orig.CompletedAt.Time.IsZero() || orig.Error.String != "" {
|
||||
err := db.UpdateProvisionerJobWithCompleteByID(genCtx, database.UpdateProvisionerJobWithCompleteByIDParams{
|
||||
ID: job.ID,
|
||||
ID: jobID,
|
||||
UpdatedAt: job.UpdatedAt,
|
||||
CompletedAt: orig.CompletedAt,
|
||||
Error: orig.Error,
|
||||
@ -353,14 +354,14 @@ func ProvisionerJob(t testing.TB, db database.Store, orig database.ProvisionerJo
|
||||
}
|
||||
if !orig.CanceledAt.Time.IsZero() {
|
||||
err := db.UpdateProvisionerJobWithCancelByID(genCtx, database.UpdateProvisionerJobWithCancelByIDParams{
|
||||
ID: job.ID,
|
||||
ID: jobID,
|
||||
CanceledAt: orig.CanceledAt,
|
||||
CompletedAt: orig.CompletedAt,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
job, err = db.GetProvisionerJobByID(genCtx, job.ID)
|
||||
job, err = db.GetProvisionerJobByID(genCtx, jobID)
|
||||
require.NoError(t, err)
|
||||
|
||||
return job
|
||||
|
@ -218,11 +218,13 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
|
||||
arg.HasAgent,
|
||||
arg.AgentInactiveDisconnectTimeoutSeconds,
|
||||
arg.LockedAt,
|
||||
arg.LastUsedBefore,
|
||||
arg.LastUsedAfter,
|
||||
arg.Offset,
|
||||
arg.Limit,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("get authorized workspaces: %w", err)
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetWorkspacesRow
|
||||
|
@ -9498,6 +9498,17 @@ WHERE
|
||||
ELSE
|
||||
locked_at IS NULL
|
||||
END
|
||||
-- Filter by last_used
|
||||
AND CASE
|
||||
WHEN $11 :: timestamp with time zone > '0001-01-01 00:00:00Z' THEN
|
||||
workspaces.last_used_at <= $11
|
||||
ELSE true
|
||||
END
|
||||
AND CASE
|
||||
WHEN $12 :: timestamp with time zone > '0001-01-01 00:00:00Z' THEN
|
||||
workspaces.last_used_at >= $12
|
||||
ELSE true
|
||||
END
|
||||
-- Authorize Filter clause will be injected below in GetAuthorizedWorkspaces
|
||||
-- @authorize_filter
|
||||
ORDER BY
|
||||
@ -9509,11 +9520,11 @@ ORDER BY
|
||||
LOWER(workspaces.name) ASC
|
||||
LIMIT
|
||||
CASE
|
||||
WHEN $12 :: integer > 0 THEN
|
||||
$12
|
||||
WHEN $14 :: integer > 0 THEN
|
||||
$14
|
||||
END
|
||||
OFFSET
|
||||
$11
|
||||
$13
|
||||
`
|
||||
|
||||
type GetWorkspacesParams struct {
|
||||
@ -9527,6 +9538,8 @@ type GetWorkspacesParams struct {
|
||||
HasAgent string `db:"has_agent" json:"has_agent"`
|
||||
AgentInactiveDisconnectTimeoutSeconds int64 `db:"agent_inactive_disconnect_timeout_seconds" json:"agent_inactive_disconnect_timeout_seconds"`
|
||||
LockedAt time.Time `db:"locked_at" json:"locked_at"`
|
||||
LastUsedBefore time.Time `db:"last_used_before" json:"last_used_before"`
|
||||
LastUsedAfter time.Time `db:"last_used_after" json:"last_used_after"`
|
||||
Offset int32 `db:"offset_" json:"offset_"`
|
||||
Limit int32 `db:"limit_" json:"limit_"`
|
||||
}
|
||||
@ -9563,6 +9576,8 @@ func (q *sqlQuerier) GetWorkspaces(ctx context.Context, arg GetWorkspacesParams)
|
||||
arg.HasAgent,
|
||||
arg.AgentInactiveDisconnectTimeoutSeconds,
|
||||
arg.LockedAt,
|
||||
arg.LastUsedBefore,
|
||||
arg.LastUsedAfter,
|
||||
arg.Offset,
|
||||
arg.Limit,
|
||||
)
|
||||
|
@ -267,6 +267,17 @@ WHERE
|
||||
ELSE
|
||||
locked_at IS NULL
|
||||
END
|
||||
-- Filter by last_used
|
||||
AND CASE
|
||||
WHEN @last_used_before :: timestamp with time zone > '0001-01-01 00:00:00Z' THEN
|
||||
workspaces.last_used_at <= @last_used_before
|
||||
ELSE true
|
||||
END
|
||||
AND CASE
|
||||
WHEN @last_used_after :: timestamp with time zone > '0001-01-01 00:00:00Z' THEN
|
||||
workspaces.last_used_at >= @last_used_after
|
||||
ELSE true
|
||||
END
|
||||
-- Authorize Filter clause will be injected below in GetAuthorizedWorkspaces
|
||||
-- @authorize_filter
|
||||
ORDER BY
|
||||
|
Reference in New Issue
Block a user