Don't panic in loop

This commit is contained in:
Kitaiti Makoto 2021-02-01 01:36:29 +09:00
parent c82c38fe52
commit 5ba823990a

View File

@ -66,10 +66,10 @@ impl ActorFactoryArgs<DbPool> for RemoteFetchActor {
} }
fn fetch_and_cache_articles(user: &Arc<User>, conn: &DbConn) { fn fetch_and_cache_articles(user: &Arc<User>, conn: &DbConn) {
for create_act in user let create_acts = user.fetch_outbox::<Create>();
.fetch_outbox::<Create>() match create_acts {
.expect("Remote user: outbox couldn't be fetched") Ok(create_acts) => {
{ for create_act in create_acts {
match create_act.create_props.object_object::<LicensedArticle>() { match create_act.create_props.object_object::<LicensedArticle>() {
Ok(article) => { Ok(article) => {
Post::from_activity(conn, article) Post::from_activity(conn, article)
@ -80,26 +80,46 @@ fn fetch_and_cache_articles(user: &Arc<User>, conn: &DbConn) {
} }
} }
} }
Err(err) => {
error!("Failed to fetch outboxes: {:?}", err);
}
}
}
fn fetch_and_cache_followers(user: &Arc<User>, conn: &DbConn) { fn fetch_and_cache_followers(user: &Arc<User>, conn: &DbConn) {
for user_id in user let follower_ids = user.fetch_followers_ids();
.fetch_followers_ids() match follower_ids {
.expect("Remote user: fetching followers error") Ok(user_ids) => {
{ for user_id in user_ids {
let follower = User::from_id(conn, &user_id, None, CONFIG.proxy()) let follower = User::from_id(conn, &user_id, None, CONFIG.proxy());
.expect("user::details: Couldn't fetch follower"); match follower {
follows::Follow::insert( Ok(follower) => {
let inserted = follows::Follow::insert(
conn, conn,
follows::NewFollow { follows::NewFollow {
follower_id: follower.id, follower_id: follower.id,
following_id: user.id, following_id: user.id,
ap_url: String::new(), ap_url: String::new(),
}, },
) );
.expect("Couldn't save follower for remote user"); if inserted.is_err() {
error!("Couldn't save follower for remote user: {:?}", user_id);
}
}
Err(err) => {
error!("Couldn't fetch follower: {:?}", err);
}
}
}
}
Err(err) => {
error!("Failed to fetch follower: {:?}", err);
}
} }
} }
fn fetch_and_cache_user(user: &Arc<User>, conn: &DbConn) { fn fetch_and_cache_user(user: &Arc<User>, conn: &DbConn) {
user.refetch(conn).expect("Couldn't update user info"); if user.refetch(conn).is_err() {
error!("Couldn't update user info: {:?}", user);
}
} }