From 535716044f274d78dab1f3d8992fc8a0b4edf80d Mon Sep 17 00:00:00 2001 From: zhulongcheng Date: Fri, 30 Nov 2018 00:38:48 +0800 Subject: [PATCH] unify task page size --- task/backend/bolt/bolt.go | 12 ++++-------- task/backend/inmem_store.go | 11 +++-------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/task/backend/bolt/bolt.go b/task/backend/bolt/bolt.go index 41c78a8785..804dfb302e 100644 --- a/task/backend/bolt/bolt.go +++ b/task/backend/bolt/bolt.go @@ -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 { diff --git a/task/backend/inmem_store.go b/task/backend/inmem_store.go index d8206aade1..57f174f72a 100644 --- a/task/backend/inmem_store.go +++ b/task/backend/inmem_store.go @@ -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)