MCPcopy
hub / github.com/dgraph-io/dgraph / paginate

Function paginate

worker/sort.go:740–772  ·  view source on GitHub ↗
(ts *pb.SortMessage, dest *pb.List, vals []types.Val)

Source from the content-addressed store, hash-verified

738}
739
740func paginate(ts *pb.SortMessage, dest *pb.List, vals []types.Val) (int, int, error) {
741 count := int(ts.Count)
742 offset := int(ts.Offset)
743 start, end := x.PageRange(count, offset, len(dest.Uids))
744
745 // For multiple sort, we need to take all equal values at the start and end.
746 // This is because the final sort order depends on other sort attributes and we can't ignore
747 // equal values at start or the end.
748 if len(ts.Order) > 1 {
749 for start < len(vals) && start > 0 {
750 eq, err := types.Equal(vals[start], vals[start-1])
751 if err != nil {
752 return 0, 0, err
753 }
754 if !eq {
755 break
756 }
757 start--
758 }
759 for end < len(dest.Uids) {
760 eq, err := types.Equal(vals[end-1], vals[end])
761 if err != nil {
762 return 0, 0, err
763 }
764 if !eq {
765 break
766 }
767 end++
768 }
769 }
770
771 return start, end, nil
772}
773
774// sortByValue fetches values and sort UIDList.
775func sortByValue(ctx context.Context, ts *pb.SortMessage, ul *pb.List,

Callers 1

sortWithoutIndexFunction · 0.85

Calls 2

PageRangeFunction · 0.92
EqualFunction · 0.92

Tested by

no test coverage detected