fix(paging): return subset of rows if page start is in the middle

This change should cover this example scenario where select ended
returning 4 rows.

Row 3
Row 4
Row 5 <- page start
Row 6

Here, only rows 5 and 6 should end up in the response. Before this
change some rows could be duplicated across adjacent search pages.
This commit is contained in:
Andrew Mayorov 2023-01-11 16:59:16 +03:00
parent e07aa2086b
commit abf6f143e5
No known key found for this signature in database
GPG Key ID: 2837C62ACFBFED5D
1 changed files with 3 additions and 2 deletions

View File

@ -422,10 +422,11 @@ accumulate_query_rows(
NCursor when NCursor < PageStart ->
{more, ResultAcc#{cursor => NCursor}};
NCursor when NCursor < PageEnd ->
SubRows = lists:nthtail(max(0, PageStart - Cursor - 1), Rows),
{more, ResultAcc#{
cursor => NCursor,
count => Count + length(Rows),
rows => [{Node, Rows} | RowsAcc]
count => Count + length(SubRows),
rows => [{Node, SubRows} | RowsAcc]
}};
NCursor when NCursor >= PageEnd ->
SubRows = lists:sublist(Rows, Limit - Count),