Skip to content
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

Add ORDER BY to most scan queries #13

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 5 additions & 3 deletions pkg/client/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (c *Client) GetGroupResource(ctx context.Context, groupID int64, resourceID

args := []interface{}{groupID, resourceID}
sb := &strings.Builder{}
_, _ = sb.WriteString(`select "id", "accessLevel" from group_resources WHERE "groupId"=$1 AND "resourceId"=$2`)
_, _ = sb.WriteString(`SELECT "id", "accessLevel" from group_resources WHERE "groupId"=$1 AND "resourceId"=$2`)

var ret GroupResource
err := pgxscan.Get(ctx, c.db, &ret, sb.String(), args...)
Expand All @@ -141,7 +141,7 @@ func (c *Client) GetGroupResourceFolderDefault(ctx context.Context, groupID int6

args := []interface{}{groupID, folderID}
sb := &strings.Builder{}
_, _ = sb.WriteString(`select "id", "accessLevel" from group_resource_folder_defaults WHERE "groupId"=$1 AND "resourceFolderId"=$2`)
_, _ = sb.WriteString(`SELECT "id", "accessLevel" from group_resource_folder_defaults WHERE "groupId"=$1 AND "resourceFolderId"=$2`)

var ret GroupResourceFolderDefault
err := pgxscan.Get(ctx, c.db, &ret, sb.String(), args...)
Expand All @@ -165,7 +165,7 @@ func (c *Client) ListGroupMembers(ctx context.Context, groupID int64, pager *Pag
args = append(args, groupID)

sb := &strings.Builder{}
_, _ = sb.WriteString(`select "id", "userId", "groupId", "isAdmin" from user_groups WHERE "groupId"=$1 `)
_, _ = sb.WriteString(`select "id", "userId", "groupId", "isAdmin" from user_groups WHERE "groupId"=$1 ORDER BY "id" `)

args = append(args, limit+1)
_, _ = sb.WriteString(fmt.Sprintf("LIMIT $%d ", len(args)))
Expand Down Expand Up @@ -235,6 +235,8 @@ func (c *Client) ListGroupsForOrg(ctx context.Context, orgID int64, pager *Pager
_, _ = sb.WriteString(`WHERE "organizationId" IS NULL `)
}

_, _ = sb.WriteString(`ORDER BY "id" `)

args = append(args, limit+1)
_, _ = sb.WriteString(fmt.Sprintf("LIMIT $%d ", len(args)))

Expand Down
2 changes: 1 addition & 1 deletion pkg/client/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (c *Client) ListOrganizations(ctx context.Context, pager *Pager) ([]*OrgMod

sb := &strings.Builder{}

_, _ = sb.WriteString(`SELECT "id", "name" FROM organizations `)
_, _ = sb.WriteString(`SELECT "id", "name" FROM organizations ORDER BY "id"`)

_, _ = sb.WriteString("LIMIT $1 ")
args = append(args, limit+1)
Expand Down
2 changes: 2 additions & 0 deletions pkg/client/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ func (c *Client) ListPagesForOrg(ctx context.Context, orgID int64, pager *Pager)
_, _ = sb.WriteString(`AND "organizationId" IS NULL `)
}

_, _ = sb.WriteString(`ORDER BY "id" `)

args = append(args, limit+1)
_, _ = sb.WriteString(fmt.Sprintf("LIMIT $%d ", len(args)))

Expand Down
1 change: 1 addition & 0 deletions pkg/client/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (c *Client) ListResourcesForOrg(ctx context.Context, orgID int64, pager *Pa
sb := &strings.Builder{}
_, _ = sb.WriteString(`select "id", "name", "type", "displayName", "environmentId", "resourceFolderId" from resources WHERE "organizationId"=$1 `)
args = append(args, orgID)
_, _ = sb.WriteString(`ORDER BY "id" `)
_, _ = sb.WriteString("LIMIT $2 ")
args = append(args, limit+1)
if offset > 0 {
Expand Down
1 change: 1 addition & 0 deletions pkg/client/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (c *Client) ListUsersForOrg(ctx context.Context, orgID int64, pager *Pager)
sb := &strings.Builder{}
_, _ = sb.WriteString(`SELECT "id", "email", "firstName", "lastName", "profilePhotoUrl", "enabled", "userName", "organizationId", "lastLoggedIn" from users WHERE "organizationId"=$1 `)
args = append(args, orgID)
_, _ = sb.WriteString(`ORDER BY "id" `)
_, _ = sb.WriteString("LIMIT $2 ")
args = append(args, limit+1)
if offset > 0 {
Expand Down
Loading