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
+9
View File
@@ -83,6 +83,15 @@ impl Blog {
.expect("Blog::list_authors: author loading error")
}
pub fn count_authors(&self, conn: &Connection) -> i64 {
use schema::blog_authors;
blog_authors::table
.filter(blog_authors::blog_id.eq(self.id))
.count()
.get_result(conn)
.expect("Blog::count_authors: count loading error")
}
pub fn find_for_author(conn: &Connection, author: &User) -> Vec<Blog> {
use schema::blog_authors;
let author_ids = blog_authors::table