Count items in database as much as possible (#344)

* Count items in database as much as possible

* Fix the tests

* Remove two useless queries

* Run pragma directive before each sqlite connection

* Pragma for tests too

* Remove debug messages
This commit is contained in:
Baptiste Gelez
2018-12-14 23:16:18 +01:00
committed by GitHub
parent b0089e59b7
commit 38302203f4
19 changed files with 109 additions and 60 deletions
+3 -3
View File
@@ -29,7 +29,7 @@ pub fn details(intl: I18n, name: String, conn: DbConn, user: Option<User>, page:
let blog = Blog::find_by_fqn(&*conn, &name)
.ok_or_else(|| render!(errors::not_found(&(&*conn, &intl.catalog, user.clone()))))?;
let posts = Post::blog_page(&*conn, &blog, page.limits());
let articles = Post::get_for_blog(&*conn, &blog); // TODO only count them in DB
let articles_count = Post::count_for_blog(&*conn, &blog);
let authors = &blog.list_authors(&*conn);
Ok(render!(blogs::details(
@@ -37,9 +37,9 @@ pub fn details(intl: I18n, name: String, conn: DbConn, user: Option<User>, page:
blog.clone(),
blog.get_fqn(&*conn),
authors,
articles.len(),
articles_count,
page.0,
Page::total(articles.len() as i32),
Page::total(articles_count as i32),
user.map(|x| x.is_author_in(&*conn, &blog)).unwrap_or(false),
posts
)))