unify task page size

pull/10616/head
zhulongcheng 2018-11-30 00:38:48 +08:00
parent d8c80fa50c
commit 535716044f
2 changed files with 7 additions and 16 deletions

View File

@ -283,21 +283,17 @@ func (s *Store) ListTasks(ctx context.Context, params backend.TaskSearchParams)
return nil, errors.New("ListTasks: org and user filters are mutually exclusive")
}
const (
defaultPageSize = 100
maxPageSize = 500
)
if params.PageSize < 0 {
return nil, errors.New("ListTasks: PageSize must be positive")
}
if params.PageSize > maxPageSize {
return nil, fmt.Errorf("ListTasks: PageSize exceeds maximum of %d", maxPageSize)
if params.PageSize > platform.TaskMaxPageSize {
return nil, fmt.Errorf("ListTasks: PageSize exceeds maximum of %d", platform.TaskMaxPageSize)
}
lim := params.PageSize
if lim == 0 {
lim = defaultPageSize
lim = platform.TaskDefaultPageSize
}
taskIDs := make([]platform.ID, 0, params.PageSize)
taskIDs := make([]platform.ID, 0, lim)
var tasks []backend.StoreTaskWithMeta
if err := s.db.View(func(tx *bolt.Tx) error {

View File

@ -134,21 +134,16 @@ func (s *inmem) ListTasks(_ context.Context, params TaskSearchParams) ([]StoreTa
return nil, errors.New("ListTasks: org and user filters are mutually exclusive")
}
const (
defaultPageSize = 100
maxPageSize = 500
)
if params.PageSize < 0 {
return nil, errors.New("ListTasks: PageSize must be positive")
}
if params.PageSize > maxPageSize {
return nil, fmt.Errorf("ListTasks: PageSize exceeds maximum of %d", maxPageSize)
if params.PageSize > platform.TaskMaxPageSize {
return nil, fmt.Errorf("ListTasks: PageSize exceeds maximum of %d", platform.TaskMaxPageSize)
}
lim := params.PageSize
if lim == 0 {
lim = defaultPageSize
lim = platform.TaskDefaultPageSize
}
out := make([]StoreTaskWithMeta, 0, lim)