-
Notifications
You must be signed in to change notification settings - Fork 886
feat: Handle pagination cases where after_id does not exist #1947
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
132784e
feat: Handle pagination cases where after_id does not exist
Emyrk 0e4a3c0
import ordering
Emyrk 303feb1
feat: Use InTx to ensure db calls are consistent
Emyrk cffcd71
fix: Use correct db inside InTx
Emyrk be23937
Ruleguard is acting strange... will move to another PR
Emyrk 1c6f546
Merge remote-tracking branch 'origin/main' into stevenmasley/paginati…
Emyrk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -830,6 +830,50 @@ func TestWorkspacesByUser(t *testing.T) { | |
}) | ||
} | ||
|
||
// TestSuspendedPagination is when the after_id is a suspended record. | ||
// The database query should still return the correct page, as the after_id | ||
// is in a subquery that finds the record regardless of its status. | ||
// This is mainly to confirm the db fake has the same behavior. | ||
func TestSuspendedPagination(t *testing.T) { | ||
t.Parallel() | ||
ctx := context.Background() | ||
client := coderdtest.New(t, &coderdtest.Options{APIRateLimit: -1}) | ||
coderdtest.CreateFirstUser(t, client) | ||
me, err := client.User(context.Background(), codersdk.Me) | ||
require.NoError(t, err) | ||
orgID := me.OrganizationIDs[0] | ||
|
||
total := 10 | ||
users := make([]codersdk.User, 0, total) | ||
// Create users | ||
for i := 0; i < total; i++ { | ||
email := fmt.Sprintf("%[email protected]", i) | ||
username := fmt.Sprintf("user%d", i) | ||
user, err := client.CreateUser(context.Background(), codersdk.CreateUserRequest{ | ||
Email: email, | ||
Username: username, | ||
Password: "password", | ||
OrganizationID: orgID, | ||
}) | ||
require.NoError(t, err) | ||
users = append(users, user) | ||
} | ||
sortUsers(users) | ||
deletedUser := users[2] | ||
expected := users[3:8] | ||
_, err = client.UpdateUserStatus(ctx, deletedUser.ID.String(), codersdk.UserStatusSuspended) | ||
require.NoError(t, err, "suspend user") | ||
|
||
page, err := client.Users(ctx, codersdk.UsersRequest{ | ||
Pagination: codersdk.Pagination{ | ||
Limit: len(expected), | ||
AfterID: deletedUser.ID, | ||
}, | ||
}) | ||
require.NoError(t, err) | ||
require.Equal(t, expected, page, "expected page") | ||
} | ||
|
||
// TestPaginatedUsers creates a list of users, then tries to paginate through | ||
// them using different page sizes. | ||
func TestPaginatedUsers(t *testing.T) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
postgres defaults to an "active" filter.