From 78f71deead112dde8279a501e88554c851f439eb Mon Sep 17 00:00:00 2001 From: alemi Date: Wed, 29 May 2024 20:26:40 +0200 Subject: [PATCH] fix: user update task without deleting --- src/cli/update.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/cli/update.rs b/src/cli/update.rs index f43c9b2e..9f3ec1c0 100644 --- a/src/cli/update.rs +++ b/src/cli/update.rs @@ -1,5 +1,5 @@ use futures::TryStreamExt; -use sea_orm::{ColumnTrait, EntityTrait, QueryFilter}; +use sea_orm::{ActiveValue::{Set, NotSet}, ColumnTrait, EntityTrait, QueryFilter}; use crate::server::fetcher::Fetcher; @@ -19,8 +19,11 @@ pub async fn update_users(ctx: crate::server::Context, days: i64) -> crate::Resu match ctx.pull_user(&user.id).await { Err(e) => tracing::warn!("could not update user {}: {e}", user.id), Ok(doc) => match crate::model::actor::ActiveModel::new(&doc) { - Ok(u) => { - insertions.push((user.id, u)); + Ok(mut u) => { + u.internal = NotSet; + u.updated = Set(chrono::Utc::now()); + let uid = u.id.take().unwrap_or(user.id.clone()); + insertions.push((uid, u)); count += 1; }, Err(e) => tracing::warn!("failed deserializing user '{}': {e}", user.id), @@ -31,8 +34,10 @@ pub async fn update_users(ctx: crate::server::Context, days: i64) -> crate::Resu for (uid, user_model) in insertions { tracing::info!("updating user {}", uid); - crate::model::actor::Entity::delete_by_ap_id(&uid).exec(ctx.db()).await?; - crate::model::actor::Entity::insert(user_model).exec(ctx.db()).await?; + crate::model::actor::Entity::update(user_model) + .filter(crate::model::actor::Column::Id.eq(uid)) + .exec(ctx.db()) + .await?; } tracing::info!("updated {count} users");