Enhance pagination and repository functionality for MongoDB
continuous-integration/drone/push Build is passing
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user