v0.0.547 allow calling ListWithCount with pageSize=0
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m55s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m55s
This commit is contained in:
@@ -215,17 +215,44 @@ func (c *Coll[TData]) Count(ctx context.Context, filter ct.RawFilter) (int64, er
|
||||
}
|
||||
|
||||
func (c *Coll[TData]) ListWithCount(ctx context.Context, filter ct.Filter, pageSize *int, inTok ct.CursorToken) ([]TData, ct.CursorToken, int64, error) {
|
||||
// NOTE: Possible optimization: Cache count in CursorToken, then fetch count only on first page.
|
||||
count, err := c.Count(ctx, filter)
|
||||
if err != nil {
|
||||
return nil, nil, 0, err
|
||||
}
|
||||
|
||||
data, token, err := c.List(ctx, filter, pageSize, inTok)
|
||||
if err != nil {
|
||||
return nil, nil, 0, err
|
||||
if pageSize != nil && *pageSize == 0 {
|
||||
|
||||
// fast track, we return an empty list and do not advance the cursor token
|
||||
|
||||
count, err := c.Count(ctx, filter)
|
||||
if err != nil {
|
||||
return nil, nil, 0, err
|
||||
}
|
||||
|
||||
return make([]TData, 0), inTok, count, nil
|
||||
|
||||
} else if pageSize == nil && inTok.IsStart() {
|
||||
|
||||
// fast track, we simply return len(entries) for count (we query all anyway)
|
||||
|
||||
data, token, err := c.List(ctx, filter, pageSize, inTok)
|
||||
if err != nil {
|
||||
return nil, nil, 0, err
|
||||
}
|
||||
|
||||
return data, token, int64(len(data)), nil
|
||||
|
||||
} else {
|
||||
|
||||
count, err := c.Count(ctx, filter)
|
||||
if err != nil {
|
||||
return nil, nil, 0, err
|
||||
}
|
||||
|
||||
data, token, err := c.List(ctx, filter, pageSize, inTok)
|
||||
if err != nil {
|
||||
return nil, nil, 0, err
|
||||
}
|
||||
|
||||
return data, token, count, nil
|
||||
|
||||
}
|
||||
return data, token, count, nil
|
||||
}
|
||||
|
||||
func (c *Coll[TData]) ListAllIDs(ctx context.Context, filter ct.RawFilter) ([]string, error) {
|
||||
|
Reference in New Issue
Block a user