Skip to content

Commit 62e009c

Browse files
committed
Fix pagination code
1 parent aa2ac99 commit 62e009c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/controllers/helpers/pagination.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use std::str::FromStr;
1717
use std::sync::Arc;
1818

1919
const MAX_PAGE_BEFORE_SUSPECTED_BOT: u32 = 10;
20-
const DEFAULT_PER_PAGE: u32 = 10;
21-
const MAX_PER_PAGE: u32 = 100;
20+
const DEFAULT_PER_PAGE: i64 = 10;
21+
const MAX_PER_PAGE: i64 = 100;
2222

2323
#[derive(Debug, Clone, PartialEq, Eq)]
2424
pub(crate) enum Page {
@@ -30,7 +30,7 @@ pub(crate) enum Page {
3030
#[derive(Debug, Clone)]
3131
pub(crate) struct PaginationOptions {
3232
pub(crate) page: Page,
33-
pub(crate) per_page: u32,
33+
pub(crate) per_page: i64,
3434
}
3535

3636
impl PaginationOptions {
@@ -42,9 +42,9 @@ impl PaginationOptions {
4242
}
4343
}
4444

45-
pub(crate) fn offset(&self) -> Option<u32> {
45+
pub(crate) fn offset(&self) -> Option<i64> {
4646
if let Page::Numeric(p) = self.page {
47-
Some((p - 1) * self.per_page)
47+
Some((p - 1) as i64 * self.per_page)
4848
} else {
4949
None
5050
}
@@ -238,10 +238,9 @@ where
238238
out.push_sql("SELECT *, COUNT(*) OVER () FROM (");
239239
self.query.walk_ast(out.reborrow())?;
240240
out.push_sql(") t LIMIT ");
241-
out.push_bind_param::<BigInt, _>((self.options.per_page as &i64))?;
241+
out.push_bind_param::<BigInt, _>(&self.options.per_page)?;
242242
if let Some(offset) = self.options.offset() {
243-
out.push_sql(" OFFSET ");
244-
out.push_bind_param::<BigInt, _>(&(offset as i64))?;
243+
out.push_sql(format!(" OFFSET {}", offset).as_str());
245244
}
246245
Ok(())
247246
}

0 commit comments

Comments
 (0)