forked from alemi/upub
fix: use .udpate method, internal unchanged
This commit is contained in:
parent
37fa1df9ab
commit
e1f1548e7e
3 changed files with 13 additions and 27 deletions
|
@ -1,4 +1,4 @@
|
|||
use sea_orm::EntityTrait;
|
||||
use sea_orm::{ActiveModelTrait, EntityTrait};
|
||||
|
||||
pub async fn fix(ctx: upub::Context, likes: bool, shares: bool, replies: bool) -> Result<(), sea_orm::DbErr> {
|
||||
use futures::TryStreamExt;
|
||||
|
@ -16,14 +16,11 @@ pub async fn fix(ctx: upub::Context, likes: bool, shares: bool, replies: bool) -
|
|||
|
||||
for (k, v) in store {
|
||||
let m = upub::model::object::ActiveModel {
|
||||
internal: sea_orm::Set(k),
|
||||
internal: sea_orm::Unchanged(k),
|
||||
likes: sea_orm::Set(v),
|
||||
..Default::default()
|
||||
};
|
||||
if let Err(e) = upub::model::object::Entity::update(m)
|
||||
.exec(db)
|
||||
.await
|
||||
{
|
||||
if let Err(e) = m.update(db).await {
|
||||
tracing::warn!("record not updated ({k}): {e}");
|
||||
}
|
||||
}
|
||||
|
@ -41,14 +38,11 @@ pub async fn fix(ctx: upub::Context, likes: bool, shares: bool, replies: bool) -
|
|||
|
||||
for (k, v) in store {
|
||||
let m = upub::model::object::ActiveModel {
|
||||
internal: sea_orm::Set(k),
|
||||
internal: sea_orm::Unchanged(k),
|
||||
announces: sea_orm::Set(v),
|
||||
..Default::default()
|
||||
};
|
||||
if let Err(e) = upub::model::object::Entity::update(m)
|
||||
.exec(db)
|
||||
.await
|
||||
{
|
||||
if let Err(e) = m.update(db).await {
|
||||
tracing::warn!("record not updated ({k}): {e}");
|
||||
}
|
||||
}
|
||||
|
@ -69,14 +63,12 @@ pub async fn fix(ctx: upub::Context, likes: bool, shares: bool, replies: bool) -
|
|||
|
||||
for (k, v) in store {
|
||||
let m = upub::model::object::ActiveModel {
|
||||
id: sea_orm::Set(k.clone()),
|
||||
id: sea_orm::Unchanged(k.clone()),
|
||||
replies: sea_orm::Set(v),
|
||||
..Default::default()
|
||||
};
|
||||
if let Err(e) = upub::model::object::Entity::update(m)
|
||||
.exec(db)
|
||||
.await
|
||||
{
|
||||
// TODO will update work with non-primary-key field??
|
||||
if let Err(e) = m.update(db).await {
|
||||
tracing::warn!("record not updated ({k}): {e}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use futures::TryStreamExt;
|
||||
use sea_orm::{ActiveValue::{Unchanged, Set}, ColumnTrait, EntityTrait, QueryFilter};
|
||||
use sea_orm::{ActiveModelTrait, ActiveValue::{Set, Unchanged}, ColumnTrait, EntityTrait, QueryFilter};
|
||||
use upub::traits::Fetcher;
|
||||
|
||||
pub async fn update_users(ctx: upub::Context, days: i64) -> Result<(), sea_orm::DbErr> {
|
||||
|
@ -33,9 +33,7 @@ pub async fn update_users(ctx: upub::Context, days: i64) -> Result<(), sea_orm::
|
|||
|
||||
for (uid, user_model) in insertions {
|
||||
tracing::info!("updating user {}", uid);
|
||||
upub::model::actor::Entity::update(user_model)
|
||||
.exec(ctx.db())
|
||||
.await?;
|
||||
user_model.update(ctx.db()).await?;
|
||||
}
|
||||
|
||||
tracing::info!("updated {count} users");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use apb::{target::Addressed, Activity, Base, Object};
|
||||
use sea_orm::{sea_query::Expr, ActiveValue::{NotSet, Set, Unchanged}, ColumnTrait, Condition, DatabaseTransaction, EntityTrait, QueryFilter, QuerySelect, SelectColumns};
|
||||
use sea_orm::{sea_query::Expr, ActiveModelTrait, ActiveValue::{NotSet, Set, Unchanged}, ColumnTrait, Condition, DatabaseTransaction, EntityTrait, QueryFilter, QuerySelect, SelectColumns};
|
||||
use crate::{ext::{AnyQuery, LoggableError}, model, traits::{fetch::Pull, Fetcher, Normalizer}};
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
@ -268,9 +268,7 @@ pub async fn update(ctx: &crate::Context, activity: impl apb::Activity, tx: &Dat
|
|||
let mut actor_model = crate::AP::actor_q(object_node.as_actor()?)?;
|
||||
actor_model.internal = Unchanged(internal_uid);
|
||||
actor_model.updated = Set(chrono::Utc::now());
|
||||
crate::model::actor::Entity::update(actor_model)
|
||||
.exec(tx)
|
||||
.await?;
|
||||
actor_model.update(tx).await?;
|
||||
},
|
||||
apb::ObjectType::Note | apb::ObjectType::Document(apb::DocumentType::Page) => {
|
||||
let internal_oid = crate::model::object::Entity::ap_to_internal(&oid, tx)
|
||||
|
@ -279,9 +277,7 @@ pub async fn update(ctx: &crate::Context, activity: impl apb::Activity, tx: &Dat
|
|||
let mut object_model = crate::AP::object_q(&object_node)?;
|
||||
object_model.internal = Unchanged(internal_oid);
|
||||
object_model.updated = Set(chrono::Utc::now());
|
||||
crate::model::object::Entity::update(object_model)
|
||||
.exec(tx)
|
||||
.await?;
|
||||
object_model.update(tx).await?;
|
||||
},
|
||||
_ => return Err(ProcessorError::Unprocessable(activity.id()?.to_string())),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue