From d8d7c42b247dae12a9624b938ab06e3ff256b1f0 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Mon, 9 Nov 2020 14:18:34 -0500 Subject: [PATCH] Use constants --- pkg/database/pagination.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/database/pagination.go b/pkg/database/pagination.go index cc9a47ff2..50acff830 100644 --- a/pkg/database/pagination.go +++ b/pkg/database/pagination.go @@ -21,6 +21,12 @@ import ( "github.com/jinzhu/gorm" ) +const ( + // maxPrevPages and maxNextPages control the "window" to show. + maxPrevPages = 5 + maxNextPages = 5 +) + // Paginate is a helper that paginates a gorm query into the given result. In // addition to reflecting into the provided result, it returns a pagination // struct. @@ -65,14 +71,14 @@ func PaginateFn(query *gorm.DB, page, limit uint64, populateFn func(query *gorm. if current := offset + limit; current < total { remaining := total - current nextPages = uint64(math.Ceil(float64(remaining) / float64(limit))) - if nextPages > 10 { - nextPages = 5 + if nextPages > maxNextPages { + nextPages = maxNextPages } } prevPages := page - 1 - if prevPages > 10 { - prevPages = 5 + if prevPages > maxPrevPages { + prevPages = maxPrevPages } var paginator pagination.Paginator