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

* Create comment in transaction. Fixes #3741

* Removing if let on comment create.
This commit is contained in:
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

View file

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