Skip to content

fix: always return number of workspaces #12380

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

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP: update code references
  • Loading branch information
mtojek committed Mar 1, 2024
commit dcff0c03d6d9294adbe08c833eb7ca31265cd6cd
4 changes: 4 additions & 0 deletions coderd/database/dbauthz/dbauthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -3438,3 +3438,7 @@ func (q *querier) GetAuthorizedUsers(ctx context.Context, arg database.GetUsersP
// GetUsers is authenticated.
return q.GetUsers(ctx, arg)
}

func (q *querier) GetWorkspacesWithoutSummary(ctx context.Context, arg database.GetWorkspacesParams) ([]database.GetWorkspacesRow, error) {
return q.db.GetWorkspacesWithoutSummary(ctx, arg)
}
13 changes: 13 additions & 0 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ func (q *FakeQuerier) convertToWorkspaceRowsNoLock(ctx context.Context, workspac
// Append a technical row with summary
rows = append(rows, database.GetWorkspacesRow{
Count: count,
Name: "*TECHNICAL_ROW*",
})
return rows
}
Expand Down Expand Up @@ -5089,6 +5090,18 @@ func (q *FakeQuerier) GetWorkspaces(ctx context.Context, arg database.GetWorkspa
return workspaceRows, err
}

func (q *FakeQuerier) GetWorkspacesWithoutSummary(ctx context.Context, arg database.GetWorkspacesParams) ([]database.GetWorkspacesRow, error) {
if err := validateDatabaseType(arg); err != nil {
return nil, err
}

workspaceRows, err := q.GetWorkspaces(ctx, arg)
if err != nil {
return nil, err
}
return workspaceRows[:len(workspaceRows)-1], err
}

func (q *FakeQuerier) GetWorkspacesEligibleForTransition(ctx context.Context, now time.Time) ([]database.Workspace, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()
Expand Down
7 changes: 7 additions & 0 deletions coderd/database/dbmetrics/dbmetrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions coderd/database/modelqueries.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func (q *sqlQuerier) GetTemplateGroupRoles(ctx context.Context, id uuid.UUID) ([

type workspaceQuerier interface {
GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspacesParams, prepared rbac.PreparedAuthorized) ([]GetWorkspacesRow, error)
GetWorkspacesWithoutSummary(ctx context.Context, arg GetWorkspacesParams) ([]GetWorkspacesRow, error)
}

// GetAuthorizedWorkspaces returns all workspaces that the user is authorized to access.
Expand Down Expand Up @@ -278,6 +279,14 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
return items, nil
}

func (q *sqlQuerier) GetWorkspacesWithoutSummary(ctx context.Context, arg GetWorkspacesParams) ([]GetWorkspacesRow, error) {
rows, err := q.GetWorkspaces(ctx, arg)
if err != nil {
return nil, err
}
return rows[:len(rows)-1], nil
}

type userQuerier interface {
GetAuthorizedUsers(ctx context.Context, arg GetUsersParams, prepared rbac.PreparedAuthorized) ([]GetUsersRow, error)
}
Expand Down
2 changes: 1 addition & 1 deletion coderd/prometheusmetrics/prometheusmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func Agents(ctx context.Context, logger slog.Logger, registerer prometheus.Regis
timer := prometheus.NewTimer(metricsCollectorAgents)
derpMap := derpMapFn()

workspaceRows, err := db.GetWorkspaces(ctx, database.GetWorkspacesParams{
workspaceRows, err := db.GetWorkspacesWithoutSummary(ctx, database.GetWorkspacesParams{
AgentInactiveDisconnectTimeoutSeconds: int64(agentInactiveDisconnectTimeout.Seconds()),
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion coderd/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func (r *remoteReporter) createSnapshot() (*Snapshot, error) {
return nil
})
eg.Go(func() error {
workspaceRows, err := r.options.Database.GetWorkspaces(ctx, database.GetWorkspacesParams{})
workspaceRows, err := r.options.Database.GetWorkspacesWithoutSummary(ctx, database.GetWorkspacesParams{})
if err != nil {
return xerrors.Errorf("get workspaces: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion coderd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (api *API) deleteTemplate(rw http.ResponseWriter, r *http.Request) {
// This is just to get the workspace count, so we use a system context to
// return ALL workspaces. Not just workspaces the user can view.
// nolint:gocritic
workspaces, err := api.Database.GetWorkspaces(dbauthz.AsSystemRestricted(ctx), database.GetWorkspacesParams{
workspaces, err := api.Database.GetWorkspacesWithoutSummary(dbauthz.AsSystemRestricted(ctx), database.GetWorkspacesParams{
TemplateIDs: []uuid.UUID{template.ID},
})
if err != nil && !errors.Is(err, sql.ErrNoRows) {
Expand Down
2 changes: 1 addition & 1 deletion coderd/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func (api *API) deleteUser(rw http.ResponseWriter, r *http.Request) {
return
}

workspaces, err := api.Database.GetWorkspaces(ctx, database.GetWorkspacesParams{
workspaces, err := api.Database.GetWorkspacesWithoutSummary(ctx, database.GetWorkspacesParams{
OwnerID: user.ID,
})
if err != nil {
Expand Down