code.gitea.io/gitea@v1.22.3/modules/indexer/internal/paginator.go (about) 1 // Copyright 2023 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package internal 5 6 import ( 7 "math" 8 9 "code.gitea.io/gitea/models/db" 10 ) 11 12 // ParsePaginator parses a db.Paginator into a skip and limit 13 func ParsePaginator(paginator *db.ListOptions, max ...int) (int, int) { 14 // Use a very large number to indicate no limit 15 unlimited := math.MaxInt32 16 if len(max) > 0 { 17 // Some indexer engines have a limit on the page size, respect that 18 unlimited = max[0] 19 } 20 21 if paginator == nil || paginator.IsListAll() { 22 // It shouldn't happen. In actual usage scenarios, there should not be requests to search all. 23 // But if it does happen, respect it and return "unlimited". 24 // And it's also useful for testing. 25 return 0, unlimited 26 } 27 28 if paginator.PageSize == 0 { 29 // Do not return any results when searching, it's used to get the total count only. 30 return 0, 0 31 } 32 33 return paginator.GetSkipTake() 34 }