feat(cli): allow limiting how many users are updated
This commit is contained in:
parent
32b7870bf2
commit
c811eb25bd
2 changed files with 13 additions and 6 deletions
|
@ -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<u64>,
|
||||
},
|
||||
|
||||
/// register a new local user
|
||||
|
@ -141,8 +145,8 @@ pub async fn run(ctx: upub::Context, command: CliCommand) -> Result<(), Box<dyn
|
|||
Ok(relay(ctx, action).await?),
|
||||
CliCommand::Fix { likes, shares, replies } =>
|
||||
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 } =>
|
||||
|
|
|
@ -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<u64>) -> 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),
|
||||
|
|
Loading…
Reference in a new issue