From 9e5fd42d484fd3f03659d399825227d684829580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Mon, 14 Mar 2022 15:23:04 +0100 Subject: [PATCH] Limit/default compose record list rest endpoint --- compose/rest/record.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/compose/rest/record.go b/compose/rest/record.go index 2b03ab4ae..5398ddb14 100644 --- a/compose/rest/record.go +++ b/compose/rest/record.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "io" + "math" "net/http" "strconv" "strings" @@ -60,6 +61,11 @@ type ( } ) +const ( + defaultRecordSearchSize uint = 500 + maxRecordSearchSize = 1000 +) + func (Record) New() *Record { return &Record{ importSession: service.DefaultImportSession, @@ -101,6 +107,12 @@ func (ctrl *Record) List(ctx context.Context, r *request.RecordList) (interface{ f.Query = r.Query } + if r.Limit == 0 { + r.Limit = defaultRecordSearchSize + } + + r.Limit = uint(math.Min(float64(r.Limit), float64(maxRecordSearchSize))) + if f.Paging, err = filter.NewPaging(r.Limit, r.PageCursor); err != nil { return nil, err }