Jelajahi Sumber

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.
Andrew Mayorov 3 tahun lalu
induk
melakukan
abf6f143e5
1 mengubah file dengan 3 tambahan dan 2 penghapusan
  1. 3 2
      apps/emqx_management/src/emqx_mgmt_api.erl

+ 3 - 2
apps/emqx_management/src/emqx_mgmt_api.erl

@@ -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),