-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[usage] Batch list workspace instances in range #10789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -191,3 +191,29 @@ func TestListWorkspaceInstancesInRange(t *testing.T) { | |
|
|
||
| require.Len(t, retrieved, len(valid)) | ||
| } | ||
|
|
||
| func TestListWorkspaceInstancesInRange_InBatches(t *testing.T) { | ||
| conn := db.ConnectForTests(t) | ||
|
|
||
| workspaceID := "gitpodio-gitpod-gyjr82jkfnd" | ||
| var instances []db.WorkspaceInstance | ||
| for i := 0; i < 1100; i++ { | ||
| instances = append(instances, dbtest.NewWorkspaceInstance(t, db.WorkspaceInstance{ | ||
| ID: uuid.New(), | ||
| WorkspaceID: workspaceID, | ||
| CreationTime: db.NewVarcharTime(time.Date(2022, 05, 15, 12, 00, 00, 00, time.UTC)), | ||
| StartedTime: db.NewVarcharTime(time.Date(2022, 05, 15, 12, 00, 00, 00, time.UTC)), | ||
| StoppedTime: db.NewVarcharTime(time.Date(2022, 05, 15, 13, 00, 00, 00, time.UTC)), | ||
| })) | ||
|
|
||
| } | ||
|
|
||
| tx := conn.CreateInBatches(&instances, 1000) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't strictly, but felt like I should start a pattern of not doing things with more than 1k entries outside batches |
||
| require.NoError(t, tx.Error) | ||
|
|
||
| startOfMay := time.Date(2022, 05, 1, 0, 00, 00, 00, time.UTC) | ||
| startOfJune := time.Date(2022, 06, 1, 0, 00, 00, 00, time.UTC) | ||
| results, err := db.ListWorkspaceInstancesInRange(context.Background(), conn, startOfMay, startOfJune) | ||
| require.NoError(t, err) | ||
| require.Len(t, results, len(instances)) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also fixes broken master due to a semantic merge.