Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Emyrk merged 6 commits intomainfromstevenmasley/pagination_after_id
Jun 2, 2022

Conversation

Emyrk
Copy link
Member

@EmyrkEmyrk commentedJun 1, 2022
edited
Loading

Throw an error to the user in these cases

  • Templateversions
  • Workspacebuilds

User pagination does not need it as suspended users still
have rows in the database


I added unit tests to confirm status codeBad Request for these cases. And confirmed theusers pagination is ok and works in both the db fake + postgres.

Throw an error to the user in these cases- Templateversions- WorkspacebuildsUser pagination does not need it as suspended users stillhave rows in the database
@EmyrkEmyrk requested a review fromdwahlerJune 1, 2022 15:04
Comment on lines +234 to +236
if len(params.Status) == 0 {
params.Status = []database.UserStatus{database.UserStatusActive}
}
Copy link
MemberAuthor

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.

if paginationParams.AfterID != uuid.Nil {
// See if the record exists first. If the record does not exist, the pagination
// query will not work.
_, err := api.Database.GetTemplateVersionByID(r.Context(), paginationParams.AfterID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think this almost entirely solves the problem, but not 100%. It handles the case where theAfterID is bogus (never existed), and where the row was deleted before the current request started, but there's still a possibility that the row is deleted betweenGetTemplateVersionByID andGetTemplateVersionsByTemplateID.

(Or alternatively, if the DB is using something like RDS with read-replicas, the row couldappear to be deleted if the two queries hit different replicas, which would break the assumption of sequential consistency. Not sure if that's something we plan to support.)

I guess even if that race happened, the consequence would just be falling back to the current behavior of returning an empty resultset, so this is still a big improvement.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yea, I was trying to do it in postgres to prevent that tiny window@dwahler, but I don't think you can raise an exception in a query. It has to be a postgres procedure, which is a headache.

I think this isgood enough.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I am dumb,@dwahler I'll put both db calls in a transaction.

dwahler reacted with thumbs up emoji
@Emyrk
Copy link
MemberAuthor

@dwahler I am going to move it to another PR since it was acting strange in CI. I'll put it back in

@EmyrkEmyrk merged commitb9983e4 intomainJun 2, 2022
@EmyrkEmyrk deleted the stevenmasley/pagination_after_id branchJune 2, 2022 14:01
kylecarbs pushed a commit that referenced this pull requestJun 10, 2022
* feat: Handle pagination cases where after_id does not existThrow an error to the user in these cases- Templateversions- WorkspacebuildsUser pagination does not need it as suspended users stillhave rows in the database
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@dwahlerdwahlerdwahler approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Emyrk@dwahler

[8]ページ先頭

©2009-2025 Movatter.jp