diff --git a/upub/cli/src/lib.rs b/upub/cli/src/lib.rs index d96c29a..beedc10 100644 --- a/upub/cli/src/lib.rs +++ b/upub/cli/src/lib.rs @@ -65,11 +65,15 @@ pub enum CliCommand { replies: bool, }, - /// update remote users + /// update remote actors Update { - #[arg(long, short, default_value_t = 7)] - /// number of days after which users should get updated + #[arg(long, short, default_value_t = 10)] + /// number of days after which actors should get updated days: i64, + + #[arg(long)] + /// stop after updating this many actors + limit: Option, }, /// register a new local user @@ -141,8 +145,8 @@ pub async fn run(ctx: upub::Context, command: CliCommand) -> Result<(), Box Ok(fix(ctx, likes, shares, replies).await?), - CliCommand::Update { days } => - Ok(update_users(ctx, days).await?), + CliCommand::Update { days, limit } => + Ok(update_users(ctx, days, limit).await?), CliCommand::Register { username, password, display_name, summary, avatar_url, banner_url } => Ok(register(ctx, username, password, display_name, summary, avatar_url, banner_url).await?), CliCommand::Nuke { for_real, delete_objects } => diff --git a/upub/cli/src/update.rs b/upub/cli/src/update.rs index 0ead0d0..6f63d51 100644 --- a/upub/cli/src/update.rs +++ b/upub/cli/src/update.rs @@ -2,7 +2,7 @@ use futures::TryStreamExt; use sea_orm::{ActiveModelTrait, ActiveValue::Set, ColumnTrait, EntityTrait, QueryFilter}; use upub::traits::Fetcher; -pub async fn update_users(ctx: upub::Context, days: i64) -> Result<(), sea_orm::DbErr> { +pub async fn update_users(ctx: upub::Context, days: i64, limit: Option) -> Result<(), sea_orm::DbErr> { let mut count = 0; let mut stream = upub::model::actor::Entity::find() .filter(upub::model::actor::Column::Updated.lt(chrono::Utc::now() - chrono::Duration::days(days))) @@ -12,6 +12,9 @@ pub async fn update_users(ctx: upub::Context, days: i64) -> Result<(), sea_orm:: while let Some(user) = stream.try_next().await? { if ctx.is_local(&user.id) { continue } + if let Some(limit) = limit { + if count >= limit { break } + } 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),