mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: remove loadtest cmd, add new scaletest cmd (#5310)
This commit is contained in:
@@ -448,7 +448,7 @@ func (q *fakeQuerier) GetUserByEmailOrUsername(_ context.Context, arg database.G
|
||||
defer q.mutex.RUnlock()
|
||||
|
||||
for _, user := range q.users {
|
||||
if (strings.EqualFold(user.Email, arg.Email) || strings.EqualFold(user.Username, arg.Username)) && user.Deleted == arg.Deleted {
|
||||
if !user.Deleted && (strings.EqualFold(user.Email, arg.Email) || strings.EqualFold(user.Username, arg.Username)) {
|
||||
return user, nil
|
||||
}
|
||||
}
|
||||
@@ -513,15 +513,14 @@ func (q *fakeQuerier) GetAuthorizedUserCount(ctx context.Context, params databas
|
||||
users = append(users, user)
|
||||
}
|
||||
|
||||
if params.Deleted {
|
||||
tmp := make([]database.User, 0, len(users))
|
||||
for _, user := range users {
|
||||
if user.Deleted {
|
||||
tmp = append(tmp, user)
|
||||
}
|
||||
// Filter out deleted since they should never be returned..
|
||||
tmp := make([]database.User, 0, len(users))
|
||||
for _, user := range users {
|
||||
if !user.Deleted {
|
||||
tmp = append(tmp, user)
|
||||
}
|
||||
users = tmp
|
||||
}
|
||||
users = tmp
|
||||
|
||||
if params.Search != "" {
|
||||
tmp := make([]database.User, 0, len(users))
|
||||
@@ -593,15 +592,14 @@ func (q *fakeQuerier) GetUsers(_ context.Context, params database.GetUsersParams
|
||||
return a.CreatedAt.Before(b.CreatedAt)
|
||||
})
|
||||
|
||||
if params.Deleted {
|
||||
tmp := make([]database.User, 0, len(users))
|
||||
for _, user := range users {
|
||||
if user.Deleted {
|
||||
tmp = append(tmp, user)
|
||||
}
|
||||
// Filter out deleted since they should never be returned..
|
||||
tmp := make([]database.User, 0, len(users))
|
||||
for _, user := range users {
|
||||
if !user.Deleted {
|
||||
tmp = append(tmp, user)
|
||||
}
|
||||
users = tmp
|
||||
}
|
||||
users = tmp
|
||||
|
||||
if params.AfterID != uuid.Nil {
|
||||
found := false
|
||||
|
||||
@@ -261,7 +261,6 @@ func (q *sqlQuerier) GetAuthorizedUserCount(ctx context.Context, arg GetFiltered
|
||||
|
||||
query := fmt.Sprintf("-- name: GetAuthorizedUserCount :one\n%s", filtered)
|
||||
row := q.db.QueryRowContext(ctx, query,
|
||||
arg.Deleted,
|
||||
arg.Search,
|
||||
pq.Array(arg.Status),
|
||||
pq.Array(arg.RbacRole),
|
||||
|
||||
@@ -43,6 +43,7 @@ type sqlcQuerier interface {
|
||||
GetDeploymentID(ctx context.Context) (string, error)
|
||||
GetFileByHashAndCreator(ctx context.Context, arg GetFileByHashAndCreatorParams) (File, error)
|
||||
GetFileByID(ctx context.Context, id uuid.UUID) (File, error)
|
||||
// This will never count deleted users.
|
||||
GetFilteredUserCount(ctx context.Context, arg GetFilteredUserCountParams) (int64, error)
|
||||
GetGitAuthLink(ctx context.Context, arg GetGitAuthLinkParams) (GitAuthLink, error)
|
||||
GetGitSSHKey(ctx context.Context, userID uuid.UUID) (GitSSHKey, error)
|
||||
@@ -97,6 +98,7 @@ type sqlcQuerier interface {
|
||||
GetUserGroups(ctx context.Context, userID uuid.UUID) ([]Group, error)
|
||||
GetUserLinkByLinkedID(ctx context.Context, linkedID string) (UserLink, error)
|
||||
GetUserLinkByUserIDLoginType(ctx context.Context, arg GetUserLinkByUserIDLoginTypeParams) (UserLink, error)
|
||||
// This will never return deleted users.
|
||||
GetUsers(ctx context.Context, arg GetUsersParams) ([]GetUsersRow, error)
|
||||
// This shouldn't check for deleted, because it's frequently used
|
||||
// to look up references to actions. eg. a user could build a workspace
|
||||
|
||||
@@ -4182,13 +4182,13 @@ SELECT
|
||||
FROM
|
||||
users
|
||||
WHERE
|
||||
users.deleted = $1
|
||||
users.deleted = false
|
||||
-- Start filters
|
||||
-- Filter by name, email or username
|
||||
AND CASE
|
||||
WHEN $2 :: text != '' THEN (
|
||||
email ILIKE concat('%', $2, '%')
|
||||
OR username ILIKE concat('%', $2, '%')
|
||||
WHEN $1 :: text != '' THEN (
|
||||
email ILIKE concat('%', $1, '%')
|
||||
OR username ILIKE concat('%', $1, '%')
|
||||
)
|
||||
ELSE true
|
||||
END
|
||||
@@ -4196,15 +4196,15 @@ WHERE
|
||||
AND CASE
|
||||
-- @status needs to be a text because it can be empty, If it was
|
||||
-- user_status enum, it would not.
|
||||
WHEN cardinality($3 :: user_status[]) > 0 THEN
|
||||
status = ANY($3 :: user_status[])
|
||||
WHEN cardinality($2 :: user_status[]) > 0 THEN
|
||||
status = ANY($2 :: user_status[])
|
||||
ELSE true
|
||||
END
|
||||
-- Filter by rbac_roles
|
||||
AND CASE
|
||||
-- @rbac_role allows filtering by rbac roles. If 'member' is included, show everyone, as everyone is a member.
|
||||
WHEN cardinality($4 :: text[]) > 0 AND 'member' != ANY($4 :: text[])
|
||||
THEN rbac_roles && $4 :: text[]
|
||||
WHEN cardinality($3 :: text[]) > 0 AND 'member' != ANY($3 :: text[])
|
||||
THEN rbac_roles && $3 :: text[]
|
||||
ELSE true
|
||||
END
|
||||
-- Authorize Filter clause will be injected below in GetAuthorizedUserCount
|
||||
@@ -4212,19 +4212,14 @@ WHERE
|
||||
`
|
||||
|
||||
type GetFilteredUserCountParams struct {
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Search string `db:"search" json:"search"`
|
||||
Status []UserStatus `db:"status" json:"status"`
|
||||
RbacRole []string `db:"rbac_role" json:"rbac_role"`
|
||||
}
|
||||
|
||||
// This will never count deleted users.
|
||||
func (q *sqlQuerier) GetFilteredUserCount(ctx context.Context, arg GetFilteredUserCountParams) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, getFilteredUserCount,
|
||||
arg.Deleted,
|
||||
arg.Search,
|
||||
pq.Array(arg.Status),
|
||||
pq.Array(arg.RbacRole),
|
||||
)
|
||||
row := q.db.QueryRowContext(ctx, getFilteredUserCount, arg.Search, pq.Array(arg.Status), pq.Array(arg.RbacRole))
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
@@ -4236,8 +4231,8 @@ SELECT
|
||||
FROM
|
||||
users
|
||||
WHERE
|
||||
(LOWER(username) = LOWER($1) OR LOWER(email) = LOWER($2))
|
||||
AND deleted = $3
|
||||
(LOWER(username) = LOWER($1) OR LOWER(email) = LOWER($2)) AND
|
||||
deleted = false
|
||||
LIMIT
|
||||
1
|
||||
`
|
||||
@@ -4245,11 +4240,10 @@ LIMIT
|
||||
type GetUserByEmailOrUsernameParams struct {
|
||||
Username string `db:"username" json:"username"`
|
||||
Email string `db:"email" json:"email"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) GetUserByEmailOrUsername(ctx context.Context, arg GetUserByEmailOrUsernameParams) (User, error) {
|
||||
row := q.db.QueryRowContext(ctx, getUserByEmailOrUsername, arg.Username, arg.Email, arg.Deleted)
|
||||
row := q.db.QueryRowContext(ctx, getUserByEmailOrUsername, arg.Username, arg.Email)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
@@ -4303,7 +4297,9 @@ const getUserCount = `-- name: GetUserCount :one
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
users WHERE deleted = false
|
||||
users
|
||||
WHERE
|
||||
deleted = false
|
||||
`
|
||||
|
||||
func (q *sqlQuerier) GetUserCount(ctx context.Context) (int64, error) {
|
||||
@@ -4319,12 +4315,12 @@ SELECT
|
||||
FROM
|
||||
users
|
||||
WHERE
|
||||
users.deleted = $1
|
||||
users.deleted = false
|
||||
AND CASE
|
||||
-- This allows using the last element on a page as effectively a cursor.
|
||||
-- This is an important option for scripts that need to paginate without
|
||||
-- duplicating or missing data.
|
||||
WHEN $2 :: uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN (
|
||||
WHEN $1 :: uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN (
|
||||
-- The pagination cursor is the last ID of the previous page.
|
||||
-- The query is ordered by the created_at field, so select all
|
||||
-- rows after the cursor.
|
||||
@@ -4334,7 +4330,7 @@ WHERE
|
||||
FROM
|
||||
users
|
||||
WHERE
|
||||
id = $2
|
||||
id = $1
|
||||
)
|
||||
)
|
||||
ELSE true
|
||||
@@ -4342,9 +4338,9 @@ WHERE
|
||||
-- Start filters
|
||||
-- Filter by name, email or username
|
||||
AND CASE
|
||||
WHEN $3 :: text != '' THEN (
|
||||
email ILIKE concat('%', $3, '%')
|
||||
OR username ILIKE concat('%', $3, '%')
|
||||
WHEN $2 :: text != '' THEN (
|
||||
email ILIKE concat('%', $2, '%')
|
||||
OR username ILIKE concat('%', $2, '%')
|
||||
)
|
||||
ELSE true
|
||||
END
|
||||
@@ -4352,30 +4348,29 @@ WHERE
|
||||
AND CASE
|
||||
-- @status needs to be a text because it can be empty, If it was
|
||||
-- user_status enum, it would not.
|
||||
WHEN cardinality($4 :: user_status[]) > 0 THEN
|
||||
status = ANY($4 :: user_status[])
|
||||
WHEN cardinality($3 :: user_status[]) > 0 THEN
|
||||
status = ANY($3 :: user_status[])
|
||||
ELSE true
|
||||
END
|
||||
-- Filter by rbac_roles
|
||||
AND CASE
|
||||
-- @rbac_role allows filtering by rbac roles. If 'member' is included, show everyone, as
|
||||
-- everyone is a member.
|
||||
WHEN cardinality($5 :: text[]) > 0 AND 'member' != ANY($5 :: text[]) THEN
|
||||
rbac_roles && $5 :: text[]
|
||||
WHEN cardinality($4 :: text[]) > 0 AND 'member' != ANY($4 :: text[]) THEN
|
||||
rbac_roles && $4 :: text[]
|
||||
ELSE true
|
||||
END
|
||||
-- End of filters
|
||||
ORDER BY
|
||||
-- Deterministic and consistent ordering of all users, even if they share
|
||||
-- a timestamp. This is to ensure consistent pagination.
|
||||
(created_at, id) ASC OFFSET $6
|
||||
(created_at, id) ASC OFFSET $5
|
||||
LIMIT
|
||||
-- A null limit means "no limit", so 0 means return all
|
||||
NULLIF($7 :: int, 0)
|
||||
NULLIF($6 :: int, 0)
|
||||
`
|
||||
|
||||
type GetUsersParams struct {
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
AfterID uuid.UUID `db:"after_id" json:"after_id"`
|
||||
Search string `db:"search" json:"search"`
|
||||
Status []UserStatus `db:"status" json:"status"`
|
||||
@@ -4400,9 +4395,9 @@ type GetUsersRow struct {
|
||||
Count int64 `db:"count" json:"count"`
|
||||
}
|
||||
|
||||
// This will never return deleted users.
|
||||
func (q *sqlQuerier) GetUsers(ctx context.Context, arg GetUsersParams) ([]GetUsersRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getUsers,
|
||||
arg.Deleted,
|
||||
arg.AfterID,
|
||||
arg.Search,
|
||||
pq.Array(arg.Status),
|
||||
|
||||
@@ -20,8 +20,8 @@ SELECT
|
||||
FROM
|
||||
users
|
||||
WHERE
|
||||
(LOWER(username) = LOWER(@username) OR LOWER(email) = LOWER(@email))
|
||||
AND deleted = @deleted
|
||||
(LOWER(username) = LOWER(@username) OR LOWER(email) = LOWER(@email)) AND
|
||||
deleted = false
|
||||
LIMIT
|
||||
1;
|
||||
|
||||
@@ -29,7 +29,9 @@ LIMIT
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
users WHERE deleted = false;
|
||||
users
|
||||
WHERE
|
||||
deleted = false;
|
||||
|
||||
-- name: GetActiveUserCount :one
|
||||
SELECT
|
||||
@@ -40,12 +42,13 @@ WHERE
|
||||
status = 'active'::user_status AND deleted = false;
|
||||
|
||||
-- name: GetFilteredUserCount :one
|
||||
-- This will never count deleted users.
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
users
|
||||
WHERE
|
||||
users.deleted = @deleted
|
||||
users.deleted = false
|
||||
-- Start filters
|
||||
-- Filter by name, email or username
|
||||
AND CASE
|
||||
@@ -127,12 +130,13 @@ WHERE
|
||||
id = $1;
|
||||
|
||||
-- name: GetUsers :many
|
||||
-- This will never return deleted users.
|
||||
SELECT
|
||||
*, COUNT(*) OVER() AS count
|
||||
FROM
|
||||
users
|
||||
WHERE
|
||||
users.deleted = @deleted
|
||||
users.deleted = false
|
||||
AND CASE
|
||||
-- This allows using the last element on a page as effectively a cursor.
|
||||
-- This is an important option for scripts that need to paginate without
|
||||
|
||||
Reference in New Issue
Block a user