Paginate the homepage

This commit is contained in:
Bat
2018-07-25 15:20:09 +02:00
parent 740393bc18
commit 18125ab398
9 changed files with 50 additions and 5 deletions
+12
View File
@@ -65,6 +65,10 @@ impl Post {
.len()
}
pub fn count(conn: &PgConnection) -> i64 {
posts::table.count().get_result(conn).expect("Couldn't count posts")
}
pub fn get_recents(conn: &PgConnection, limit: i64) -> Vec<Post> {
posts::table.order(posts::creation_date.desc())
.limit(limit)
@@ -106,6 +110,14 @@ impl Post {
.expect("Error loading a page of posts for blog")
}
pub fn get_recents_page(conn: &PgConnection, (min, max): (i32, i32)) -> Vec<Post> {
posts::table.order(posts::creation_date.desc())
.offset(min.into())
.limit((max - min).into())
.load::<Post>(conn)
.expect("Error loading recent posts page")
}
pub fn get_authors(&self, conn: &PgConnection) -> Vec<User> {
use schema::users;
use schema::post_authors;