fix(cli): better update task for users

This commit is contained in:
əlemi 2024-07-17 22:24:36 +02:00
parent 64cb963282
commit 01984c9e98
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -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(())