Files
CrimsonandGitHub 538a2d0de2 chore: Refactor models and other shareable packages into importable pkg (#762)
* Move models and other shareable code to pkg/domain and add own go.mod

* Update all references to use pkg/domain paths

* Fix generated file

* Ensure pkg/domain tests are run by just tests

* Use new models path in connector templates

* Copy local pkg/domain in dockerfile

* Ensure pkg/domain is subject to go generate
2026-06-23 13:08:32 +00:00

30 lines
1.1 KiB
Go

package pagination
// ShouldFetchMore determines if we need more objects to fetch and if we have
// more objects to fetch.
// This function should be used only if the following requirements are met:
// - When fetching some objects, you need to append all of them to a slice
func ShouldFetchMore[T any, C any](total []T, currentBatch []C, pageSize int) (needMore bool, hasMore bool) {
switch {
case len(total) > pageSize:
// We fetched more than we should, the total will be trimed, we don't
// need more
needMore = false
// Since the total will be trimed it means we will have to refetch the
// objects trimed, so we have more
hasMore = true
case len(total) == pageSize:
// We don't need more, we fetched exactly what we needed
needMore = false
// hasMore depennds on the currentBatch, if the currentBatch is full
// then we have more
hasMore = len(currentBatch) >= pageSize
default:
// Here, total is < pageSize, so we need more objects
needMore = true
// If the currentBatch is full, we have more
hasMore = len(currentBatch) >= pageSize
}
return
}