diff --git a/upub/cli/src/update.rs b/upub/cli/src/update.rs index 4b48a6f..0ead0d0 100644 --- a/upub/cli/src/update.rs +++ b/upub/cli/src/update.rs @@ -4,37 +4,29 @@ use upub::traits::Fetcher; pub async fn update_users(ctx: upub::Context, days: i64) -> Result<(), sea_orm::DbErr> { let mut count = 0; - let mut insertions = Vec::new(); - - { - let mut stream = upub::model::actor::Entity::find() - .filter(upub::model::actor::Column::Updated.lt(chrono::Utc::now() - chrono::Duration::days(days))) - .stream(ctx.db()) - .await?; + let mut stream = upub::model::actor::Entity::find() + .filter(upub::model::actor::Column::Updated.lt(chrono::Utc::now() - chrono::Duration::days(days))) + .stream(ctx.db()) + .await?; - while let Some(user) = stream.try_next().await? { - if ctx.is_local(&user.id) { continue } - match ctx.pull(&user.id).await.map(|x| x.actor()) { - Err(e) => tracing::warn!("could not update user {}: {e}", user.id), - Ok(Err(e)) => tracing::warn!("could not update user {}: {e}", user.id), - Ok(Ok(doc)) => match upub::AP::actor_q(&doc, Some(user.internal)) { - Ok(mut u) => { - u.updated = Set(chrono::Utc::now()); - insertions.push((user.id, u)); - count += 1; - }, - Err(e) => tracing::warn!("failed deserializing user '{}': {e}", user.id), + while let Some(user) = stream.try_next().await? { + if ctx.is_local(&user.id) { continue } + match ctx.pull(&user.id).await.map(|x| x.actor()) { + Err(e) => tracing::warn!("could not update user {}: {e}", user.id), + Ok(Err(e)) => tracing::warn!("could not update user {}: {e}", user.id), + Ok(Ok(doc)) => match upub::AP::actor_q(&doc, Some(user.internal)) { + Ok(mut u) => { + tracing::info!("updating user {}", user.id); + u.updated = Set(chrono::Utc::now()); + u.update(ctx.db()).await?; + count += 1; }, - } + Err(e) => tracing::warn!("failed deserializing user '{}': {e}", user.id), + }, } } - for (uid, user_model) in insertions { - tracing::info!("updating user {}", uid); - user_model.update(ctx.db()).await?; - } - tracing::info!("updated {count} users"); Ok(())