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

Support pagination for tagserver #190

Merged
merged 1 commit into from
Jul 23, 2019
Merged

Support pagination for tagserver #190

merged 1 commit into from
Jul 23, 2019

Conversation

rmalpani-uber
Copy link
Contributor

  • Support pagination in list and listRespositories handler
  • Fix bug in gcsbackend pagination
  • Response for list with pagination
    type ListResponse struct {
    Links struct {
    Next string json:"next"
    Self string json:"self"
    }
    Size int json:"size"
    Result []string json:"result"
    }

{
"Links": {
"next": "/list/?limit=3&offset=ClEvdGVzdC1idWNrZXQva3Jha2VuL2RlZmF1bHQvZG9ja2VyL3JlZ2lzdHJ5L3YyL2Jsb2JzL3NoYTI1Ni9hbC9hbHBpbmU6bGF0ZXN0L2RhdGE%3D",
"self": "/list/?limit=3&offset=CoQBL3Rlc3QtYnVja2V0L2tyYWtlbi9kZWZhdWx0L2RvY2tlci9yZWdpc3RyeS92Mi9ibG9icy9zaGEyNTYvNTcvNTczMzRjNTA5NTlmMjZjZTFlZTAyNWQwOGYxMzZjMjI5MmMxMjhmODRlN2IyMjlkMWIwZGE1ZGFjODllOTg2Ni9kYXRh"
},
"size": 3,
"result": [
"/test-bucket/kraken/default/docker/registry/v2/blobs/sha256/92/921b31ab772b38172fd9f942a40fae6db24decbd6706f67836260d47a72baab5/data",
"/test-bucket/kraken/default/docker/registry/v2/blobs/sha256/97/97a042bf09f1bf78c8cf3dcebef94614f2b95fa2f988a5c07314031bc2570c7a/data",
"/test-bucket/kraken/default/docker/registry/v2/blobs/sha256/al/alpine:latest/data"
]
}

return nil, handler.Errorf(
"invalid query %s:%s", k, v).Status(http.StatusBadRequest)
}
if k == limitQ {
Copy link
Collaborator

Choose a reason for hiding this comment

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

use switch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just 3 case, same perf and readable. Let me know if you think switch is more readable?

Copy link
Collaborator

Choose a reason for hiding this comment

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

i think it would be slightly more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

"invalid query %s", k).Status(http.StatusBadRequest)
}
}
if len(q) > 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

len(q) > 0 does not really map to // Enable pagination if either or both of the query param exists.. Maybe it is better to define an explicit variable like enablePagination.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If query exists, we are validating it above. If its validate, it would be related to pagination as of current implementation. But I think enablePagination would make it more readable too. Will fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe len(opts) would be good check.

opts = append(opts, backend.ListWithPagination())
}

return &opts, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

why returning reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Avoiding slice header allocation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm i dont think we really worry about slice allocation here...I wouldnt return a pointer to a list unless it is really necessary. Also, if you return just []backend.ListOption, then you don't need to check nil in the caller above^.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

if err != nil {
return err
}
if opts == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

i wonder if client.List(path.Join(repo, "_manifests/tags"), opts...) should handle the case when opts is empty...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

return nil, handler.Errorf(
"invalid query %s:%s", k, v).Status(http.StatusBadRequest)
}
if k == limitQ {
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think it would be slightly more readable.

opts = append(opts, backend.ListWithPagination())
}

return &opts, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm i dont think we really worry about slice allocation here...I wouldnt return a pointer to a list unless it is really necessary. Also, if you return just []backend.ListOption, then you don't need to check nil in the caller above^.

if err != nil {
return err
}
if opts == nil {
return handler.Errorf("internal error")
Copy link
Collaborator

Choose a reason for hiding this comment

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

return something more meaningful here?

+ Support pagination in list and listRespositories handler
+ Fix bug in gcsbackend pagination
+ Response for list with pagination
type ListResponse struct {
       Links struct {
               Next string `json:"next"`
               Self string `json:"self"`
       }
       Size   int      `json:"size"`
       Result []string `json:"result"`
}
@evelynl94 evelynl94 merged commit 61747f2 into uber:master Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants