Skip to content

fix: Adjust pagination limit to be zero-based #2663

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

Merged
merged 5 commits into from
Jun 26, 2022
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
2 changes: 1 addition & 1 deletion coderd/coderdtest/coderdtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func AwaitWorkspaceAgents(t *testing.T, client *codersdk.Client, build uuid.UUID
}
}
return true
}, 5*time.Second, 25*time.Millisecond)
}, 15*time.Second, 50*time.Millisecond)
return resources
}

Expand Down
12 changes: 6 additions & 6 deletions coderd/database/queries.sql.go

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

4 changes: 2 additions & 2 deletions coderd/database/queries/templateversions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ ORDER BY
-- a timestamp. This is to ensure consistent pagination.
(created_at, id) ASC OFFSET @offset_opt
LIMIT
-- A null limit means "no limit", so -1 means return all
NULLIF(@limit_opt :: int, -1);
-- A null limit means "no limit", so 0 means return all
NULLIF(@limit_opt :: int, 0);

-- name: GetTemplateVersionByJobID :one
SELECT
Expand Down
4 changes: 2 additions & 2 deletions coderd/database/queries/users.sql
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ ORDER BY
-- a timestamp. This is to ensure consistent pagination.
(created_at, id) ASC OFFSET @offset_opt
LIMIT
-- A null limit means "no limit", so -1 means return all
NULLIF(@limit_opt :: int, -1);
-- A null limit means "no limit", so 0 means return all
NULLIF(@limit_opt :: int, 0);

-- name: UpdateUserStatus :one
UPDATE
Expand Down
4 changes: 2 additions & 2 deletions coderd/database/queries/workspacebuilds.sql
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ END
ORDER BY
build_number desc OFFSET @offset_opt
LIMIT
-- A null limit means "no limit", so -1 means return all
NULLIF(@limit_opt :: int, -1);
-- A null limit means "no limit", so 0 means return all
NULLIF(@limit_opt :: int, 0);

-- name: GetLatestWorkspaceBuildByWorkspaceID :one
SELECT
Expand Down
2 changes: 1 addition & 1 deletion coderd/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func parsePagination(w http.ResponseWriter, r *http.Request) (p codersdk.Paginat
params := codersdk.Pagination{
AfterID: parser.UUID(queryParams, uuid.Nil, "after_id"),
// Limit default to "-1" which returns all results
Limit: parser.Int(queryParams, -1, "limit"),
Limit: parser.Int(queryParams, 0, "limit"),
Offset: parser.Int(queryParams, 0, "offset"),
}
if len(parser.Errors) > 0 {
Expand Down
2 changes: 0 additions & 2 deletions coderd/pagination_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,13 @@ func TestPagination(t *testing.T) {
ExpectedParams: codersdk.Pagination{
AfterID: uuid.Nil,
Offset: 150,
Limit: -1,
},
},
{
Name: "ValidAfterID",
AfterID: "5f2005fc-acc4-4e5e-a7fa-be017359c60b",
ExpectedParams: codersdk.Pagination{
AfterID: uuid.MustParse("5f2005fc-acc4-4e5e-a7fa-be017359c60b"),
Limit: -1,
},
},
}
Expand Down