fix(cli): better update task for users
This commit is contained in:
parent
64cb963282
commit
01984c9e98
1 changed files with 17 additions and 25 deletions
|
@ -4,9 +4,6 @@ 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) -> Result<(), sea_orm::DbErr> {
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
let mut insertions = Vec::new();
|
|
||||||
|
|
||||||
{
|
|
||||||
let mut stream = upub::model::actor::Entity::find()
|
let mut stream = upub::model::actor::Entity::find()
|
||||||
.filter(upub::model::actor::Column::Updated.lt(chrono::Utc::now() - chrono::Duration::days(days)))
|
.filter(upub::model::actor::Column::Updated.lt(chrono::Utc::now() - chrono::Duration::days(days)))
|
||||||
.stream(ctx.db())
|
.stream(ctx.db())
|
||||||
|
@ -20,20 +17,15 @@ pub async fn update_users(ctx: upub::Context, days: i64) -> Result<(), sea_orm::
|
||||||
Ok(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(Ok(doc)) => match upub::AP::actor_q(&doc, Some(user.internal)) {
|
||||||
Ok(mut u) => {
|
Ok(mut u) => {
|
||||||
|
tracing::info!("updating user {}", user.id);
|
||||||
u.updated = Set(chrono::Utc::now());
|
u.updated = Set(chrono::Utc::now());
|
||||||
insertions.push((user.id, u));
|
u.update(ctx.db()).await?;
|
||||||
count += 1;
|
count += 1;
|
||||||
},
|
},
|
||||||
Err(e) => tracing::warn!("failed deserializing user '{}': {e}", user.id),
|
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");
|
tracing::info!("updated {count} users");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue