Skip to content

Commit 454f35d

Browse files
committed
controllers/helpers/pagination: Handle null next_page for seek-based pagination
...when seeking backward involved.
1 parent 7b91ca3 commit 454f35d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/controllers/helpers/pagination.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,20 @@ impl<T> Paginated<T> {
254254
F: Fn(&T) -> S,
255255
S: Serialize,
256256
{
257-
// TODO: handle this more properly when seek backward comes into play.
257+
// When the data size is smaller than the page size, we would expect the next page to be
258+
// available during backward pagination but unavailable during forward pagination.
258259
if self.options.is_explicit()
259-
|| self.records_and_total.len() < self.options.per_page as usize
260+
|| self.records_and_total.is_empty()
261+
|| (self.records_and_total.len() < self.options.per_page as usize
262+
&& !self.options.is_backward())
260263
{
261264
return Ok(None);
262265
}
263266

267+
// We also like to return None for next page when it's the first backward pagination.
264268
let mut opts = IndexMap::new();
265269
match self.options.page {
270+
Page::SeekBackward(ref raw) if raw.is_empty() => return Ok(None),
266271
Page::Unspecified | Page::Seek(_) | Page::SeekBackward(_) => {
267272
let seek = f(&self.records_and_total.last().unwrap().record);
268273
opts.insert("seek".into(), encode_seek(seek)?);

0 commit comments

Comments
 (0)