Improve the background article fetching code

This commit is contained in:
Bat
2018-07-26 22:59:41 +02:00
parent bd259891f3
commit 0314629d99
3 changed files with 62 additions and 54 deletions
+12 -10
View File
@@ -47,18 +47,20 @@ fn details<'r>(name: String, conn: DbConn, account: Option<User>, worker: State<
let n_followers = user.get_followers(&*conn).len();
// Fetch new articles
let user_clone = user.clone();
worker.execute(Thunk::of(move || {
for create_act in user_clone.fetch_outbox::<Create>() {
match create_act.create_props.object_object::<Article>() {
Ok(article) => {
Post::from_activity(&*other_conn, article, user_clone.clone().into_id());
println!("Fetched article from remote user");
if !user.get_instance(&*conn).local {
let user_clone = user.clone();
worker.execute(Thunk::of(move || {
for create_act in user_clone.fetch_outbox::<Create>() {
match create_act.create_props.object_object::<Article>() {
Ok(article) => {
Post::from_activity(&*other_conn, article, user_clone.clone().into_id());
println!("Fetched article from remote user");
}
Err(e) => println!("Error while fetching articles in background: {:?}", e)
}
Err(e) => println!("Error while fetching articles in background: {:?}", e)
}
}
}));
}));
}
Template::render("users/details", json!({
"user": user.to_json(&*conn),