fix: oops forgot to commit but also no need for tx

in case of failures mid-way, this allows restarting it multiple times
and still succeeding
This commit is contained in:
əlemi 2024-07-15 23:58:50 +02:00
parent 1f1ebbb69a
commit 5a5c47ecbc
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -3,8 +3,6 @@ use sea_orm::{ActiveModelTrait, ActiveValue::{Set, Unchanged}, ColumnTrait, Enti
use upub::traits::{fetch::RequestError, Cloaker}; use upub::traits::{fetch::RequestError, Cloaker};
pub async fn cloak(ctx: upub::Context, post_contents: bool) -> Result<(), RequestError> { pub async fn cloak(ctx: upub::Context, post_contents: bool) -> Result<(), RequestError> {
let tx = ctx.db().begin().await?;
{ {
let mut stream = upub::model::attachment::Entity::find() let mut stream = upub::model::attachment::Entity::find()
.filter(upub::model::attachment::Column::Url.not_like(format!("{}%", ctx.base()))) .filter(upub::model::attachment::Column::Url.not_like(format!("{}%", ctx.base())))
@ -16,7 +14,7 @@ pub async fn cloak(ctx: upub::Context, post_contents: bool) -> Result<(), Reques
let (sig, url) = ctx.cloak(&attachment.url); let (sig, url) = ctx.cloak(&attachment.url);
let mut model = attachment.into_active_model(); let mut model = attachment.into_active_model();
model.url = Set(upub::url!(ctx, "/proxy/{sig}/{url}")); model.url = Set(upub::url!(ctx, "/proxy/{sig}/{url}"));
model.update(&tx).await?; model.update(ctx.db()).await?;
} }
} }
@ -39,7 +37,7 @@ pub async fn cloak(ctx: upub::Context, post_contents: bool) -> Result<(), Reques
content: Set(Some(sanitized)), content: Set(Some(sanitized)),
..Default::default() ..Default::default()
}; };
model.update(&tx).await?; model.update(ctx.db()).await?;
} }
} }
} }