Create comment in transaction. Fixes #3741 (#4265)

* Create comment in transaction. Fixes #3741

* Removing if let on comment create.
pull/4279/head
Dessalines 2023-12-15 05:36:58 -05:00 committed by GitHub
parent 246e38a45b
commit 719b76a6e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 51 additions and 48 deletions

View File

@ -59,6 +59,10 @@ impl Comment {
) -> Result<Comment, Error> {
let conn = &mut get_conn(pool).await?;
conn
.build_transaction()
.run(|conn| {
Box::pin(async move {
// Insert, to get the id
let inserted_comment = insert_into(comment)
.values(comment_form)
@ -66,10 +70,9 @@ impl Comment {
.do_update()
.set(comment_form)
.get_result::<Self>(conn)
.await;
.await?;
if let Ok(comment_insert) = inserted_comment {
let comment_id = comment_insert.id;
let comment_id = inserted_comment.id;
// You need to update the ltree column
let ltree = Ltree(if let Some(parent_path) = parent_path {
@ -119,9 +122,9 @@ where ca.comment_id = c.id"
}
}
updated_comment
} else {
inserted_comment
}
}) as _
})
.await
}
pub async fn read_from_apub_id(
pool: &mut DbPool<'_>,