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

Commit784bb6d

Browse files
committed
fix: always show a newly created workspace at the top of the list
Fixes#5795.
1 parent95e578b commit784bb6d

File tree

6 files changed

+16
-53
lines changed

6 files changed

+16
-53
lines changed

‎coderd/database/dbfake/databasefake.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3357,6 +3357,7 @@ func (q *fakeQuerier) InsertWorkspace(_ context.Context, arg database.InsertWork
33573357
Name:arg.Name,
33583358
AutostartSchedule:arg.AutostartSchedule,
33593359
Ttl:arg.Ttl,
3360+
LastUsedAt:arg.LastUsedAt,
33603361
}
33613362
q.workspaces=append(q.workspaces,workspace)
33623363
returnworkspace,nil

‎coderd/database/dbgen/generator.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func Workspace(t testing.TB, db database.Store, orig database.Workspace) databas
145145
UpdatedAt:takeFirst(orig.UpdatedAt,database.Now()),
146146
OrganizationID:takeFirst(orig.OrganizationID,uuid.New()),
147147
TemplateID:takeFirst(orig.TemplateID,uuid.New()),
148+
LastUsedAt:takeFirst(orig.LastUsedAt,database.Now()),
148149
Name:takeFirst(orig.Name,namesgenerator.GetRandomName(1)),
149150
AutostartSchedule:orig.AutostartSchedule,
150151
Ttl:orig.Ttl,

‎coderd/database/queries.sql.go‎

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

‎coderd/database/queries/workspaces.sql‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,11 @@ INSERT INTO
270270
template_id,
271271
name,
272272
autostart_schedule,
273-
ttl
273+
ttl,
274+
last_used_at
274275
)
275276
VALUES
276-
($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING*;
277+
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING*;
277278

278279
-- name: UpdateWorkspaceDeletedByID :exec
279280
UPDATE

‎coderd/insights_test.go‎

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
package coderd_test
22

33
import (
4-
"context"
54
"testing"
65
"time"
76

87
"github.com/google/uuid"
9-
"github.com/stretchr/testify/assert"
108
"github.com/stretchr/testify/require"
119

12-
"cdr.dev/slog/sloggers/slogtest"
13-
"github.com/coder/coder/agent"
1410
"github.com/coder/coder/coderd/coderdtest"
1511
"github.com/coder/coder/codersdk"
16-
"github.com/coder/coder/codersdk/agentsdk"
1712
"github.com/coder/coder/provisioner/echo"
1813
"github.com/coder/coder/testutil"
1914
)
@@ -40,44 +35,6 @@ func TestDeploymentInsights(t *testing.T) {
4035
coderdtest.AwaitTemplateVersionJob(t,client,version.ID)
4136
workspace:=coderdtest.CreateWorkspace(t,client,user.OrganizationID,template.ID)
4237
coderdtest.AwaitWorkspaceBuildJob(t,client,workspace.LatestBuild.ID)
43-
44-
agentClient:=agentsdk.New(client.URL)
45-
agentClient.SetSessionToken(authToken)
46-
agentCloser:=agent.New(agent.Options{
47-
Logger:slogtest.Make(t,nil),
48-
Client:agentClient,
49-
})
50-
deferfunc() {
51-
_=agentCloser.Close()
52-
}()
53-
resources:=coderdtest.AwaitWorkspaceAgents(t,client,workspace.ID)
54-
55-
ctx,cancel:=context.WithTimeout(context.Background(),testutil.WaitLong)
56-
defercancel()
57-
58-
daus,err:=client.DeploymentDAUs(context.Background())
59-
require.NoError(t,err)
60-
61-
require.Equal(t,&codersdk.DeploymentDAUsResponse{
62-
Entries: []codersdk.DAUEntry{},
63-
},daus,"no DAUs when stats are empty")
64-
65-
res,err:=client.Workspaces(ctx, codersdk.WorkspaceFilter{})
66-
require.NoError(t,err)
67-
assert.Zero(t,res.Workspaces[0].LastUsedAt)
68-
69-
conn,err:=client.DialWorkspaceAgent(ctx,resources[0].Agents[0].ID,&codersdk.DialWorkspaceAgentOptions{
70-
Logger:slogtest.Make(t,nil).Named("tailnet"),
71-
})
72-
require.NoError(t,err)
73-
deferfunc() {
74-
_=conn.Close()
75-
}()
76-
77-
sshConn,err:=conn.SSHClient(ctx)
78-
require.NoError(t,err)
79-
_=sshConn.Close()
80-
8138
wantDAUs:=&codersdk.DeploymentDAUsResponse{
8239
Entries: []codersdk.DAUEntry{
8340
{
@@ -86,7 +43,10 @@ func TestDeploymentInsights(t *testing.T) {
8643
},
8744
},
8845
}
46+
ctx:=testutil.Context(t,testutil.WaitMedium)
47+
vardaus*codersdk.DeploymentDAUsResponse
8948
require.Eventuallyf(t,func()bool {
49+
varerrerror
9050
daus,err=client.DeploymentDAUs(ctx)
9151
require.NoError(t,err)
9252
returnlen(daus.Entries)>0
@@ -97,10 +57,4 @@ func TestDeploymentInsights(t *testing.T) {
9757
gotDAUs,err:=client.DeploymentDAUs(ctx)
9858
require.NoError(t,err)
9959
require.Equal(t,gotDAUs,wantDAUs)
100-
101-
template,err=client.Template(ctx,template.ID)
102-
require.NoError(t,err)
103-
104-
res,err=client.Workspaces(ctx, codersdk.WorkspaceFilter{})
105-
require.NoError(t,err)
10660
}

‎coderd/workspaces.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,9 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req
480480
Name:createWorkspace.Name,
481481
AutostartSchedule:dbAutostartSchedule,
482482
Ttl:dbTTL,
483+
// The workspaces page will sort by last used at, and it's useful to
484+
// have the newly created workspace at the top of the list!
485+
LastUsedAt:database.Now(),
483486
})
484487
iferr!=nil {
485488
returnxerrors.Errorf("insert workspace: %w",err)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp