Add pagination for query to get records #58

Merged
nabarun merged 8 commits from pm-add-pagination into main 2024-09-05 07:33:49 +00:00
2 changed files with 26 additions and 7 deletions
Showing only changes of commit 2bab2eeb9b - Show all commits

View File

@ -24,6 +24,9 @@ const DefaultLogNumLines = 50
// MaxLogNumLines is the max number of log lines that can be tailed. // MaxLogNumLines is the max number of log lines that can be tailed.
const MaxLogNumLines = 1000 const MaxLogNumLines = 1000
// Whether to use default page limit when pagination args are not passed.
const UseDefaultPagination = false
type Resolver struct { type Resolver struct {
ctx client.Context ctx client.Context
logFile string logFile string
@ -140,12 +143,23 @@ func (q queryResolver) LookupNames(ctx context.Context, names []string) ([]*Name
func (q queryResolver) QueryRecords(ctx context.Context, attributes []*KeyValueInput, all *bool, limit *int, offset *int) ([]*Record, error) { func (q queryResolver) QueryRecords(ctx context.Context, attributes []*KeyValueInput, all *bool, limit *int, offset *int) ([]*Record, error) {
nsQueryClient := registrytypes.NewQueryClient(q.ctx) nsQueryClient := registrytypes.NewQueryClient(q.ctx)
pagination := &query.PageRequest{} var pagination *query.PageRequest
if limit != nil {
pagination.Limit = uint64(*limit) // Use defaults only if limit and offset not provided
} // and UseDefaultPagination is true
if offset != nil { if limit == nil && offset == nil {
pagination.Offset = uint64(*offset) if UseDefaultPagination {
pagination = &query.PageRequest{}
}
} else {
pagination = &query.PageRequest{}
if limit != nil {
pagination.Limit = uint64(*limit)
}
if offset != nil {
pagination.Offset = uint64(*offset)
}
} }
res, err := nsQueryClient.Records( res, err := nsQueryClient.Records(

View File

@ -48,7 +48,12 @@ func (qs queryServer) Records(c context.Context, req *registrytypes.QueryRecords
return nil, err return nil, err
} }
} else { } else {
records, pageResp, err = qs.k.PaginatedListRecords(ctx, req.Pagination) if req.Pagination != nil {
records, pageResp, err = qs.k.PaginatedListRecords(ctx, req.Pagination)
} else {
records, err = qs.k.ListRecords(ctx)
}
if err != nil { if err != nil {
return nil, err return nil, err
} }