Skip to content

Commit 193a57d

Browse files
committed
controllers/helpers/pagination: Maintain consistent ordering from page to page
For instance, given rows with the following: | a | b | c | ... | 1 | 2 | 3 | When performing forward seek pagination with page size as 3 to the last page, let's say we have the last page as 1, 2, 3. When performing backward seek pagination, we reverse the order of the query so that we can retrieve the data from the tail. This results in 3, 2, 1. However, we would like to maintain consistent ordering as we view it with forward pagination, namely 1, 2, 3. Therefore, we need to reverse the results again to maintain the original ordering.
1 parent 454f35d commit 193a57d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/controllers/helpers/pagination.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,12 @@ impl<T> PaginatedQuery<T> {
313313
let future = self.internal_load(conn);
314314

315315
async move {
316-
let records_and_total = future.await?.try_collect().await?;
316+
let mut records_and_total: Vec<_> = future.await?.try_collect().await?;
317317

318-
// TODO: maintain consistent ordering from page to pagen
318+
// This maintain consistent ordering from page to pagen
319+
if options.is_backward() {
320+
records_and_total.reverse();
321+
}
319322

320323
Ok(Paginated {
321324
records_and_total,
@@ -467,9 +470,12 @@ impl<T, C> PaginatedQueryWithCountSubq<T, C> {
467470
let future = self.internal_load(conn);
468471

469472
async move {
470-
let records_and_total = future.await?.try_collect().await?;
473+
let mut records_and_total: Vec<_> = future.await?.try_collect().await?;
471474

472-
// TODO: maintain consistent ordering from page to pagen
475+
// This maintain consistent ordering from page to pagen
476+
if options.is_backward() {
477+
records_and_total.reverse();
478+
}
473479

474480
Ok(Paginated {
475481
records_and_total,

0 commit comments

Comments
 (0)