Enhance pagination and repository functionality for MongoDB
continuous-integration/drone/push Build is passing

- Updated the ListPaginationOptions struct to include SkipCount and IncludeCount fields, allowing for more flexible pagination behavior.
- Modified the BuildListPagination function to handle cursor pagination with count options, improving performance by running count queries in parallel with data retrieval.
- Enhanced the FindAll method in the repository to support concurrent counting of documents, reducing overall latency for list operations.
- Added tests for pagination behavior, ensuring accurate handling of count scenarios in both offset and cursor pagination.

This update improves the efficiency and flexibility of pagination in the MongoDB repository, enhancing the overall performance of list operations.
This commit is contained in:
Mazyar
2026-06-30 18:35:34 +03:30
parent 20ce9c53ff
commit 7aacb7dfc9
4 changed files with 82 additions and 11 deletions
+11 -1
View File
@@ -15,7 +15,9 @@ const (
// ListPaginationOptions configures optional list pagination behavior.
type ListPaginationOptions struct {
Projection bson.M
Projection bson.M
SkipCount bool
IncludeCount bool // when true, count even when using cursor pagination
}
// BuildListPagination converts API pagination parameters into MongoDB pagination options.
@@ -55,6 +57,14 @@ func BuildListPagination(
pb.Projection(opts.Projection)
}
skipCount := opts.SkipCount
if cursor != "" && !opts.IncludeCount {
skipCount = true
}
if skipCount {
pb.SkipCount(true)
}
if cursor != "" {
pageCursor, err := decodePageCursor(cursor)
if err != nil {