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
@@ -56,16 +56,16 @@ impl Comment {
Post::get(conn, self.post_id).expect("Comment::get_post: post error")
}
pub fn count_local(conn: &Connection) -> usize {
pub fn count_local(conn: &Connection) -> i64 {
use schema::users;
let local_authors = users::table
.filter(users::instance_id.eq(Instance::local_id(conn)))
.select(users::id);
comments::table
.filter(comments::author_id.eq_any(local_authors))
.load::<Comment>(conn)
.count()
.get_result(conn)
.expect("Comment::count_local: loading error")
.len() // TODO count in database?
}
pub fn get_responses(&self, conn: &Connection) -> Vec<Comment> {