From aa826fd57fc26fc7dbb85b915572a157804fa3df Mon Sep 17 00:00:00 2001 From: silverpill Date: Wed, 29 Sep 2021 12:12:45 +0000 Subject: [PATCH] Update reply counts when deleting profile --- src/models/profiles/queries.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/models/profiles/queries.rs b/src/models/profiles/queries.rs index 52bdc44..58c6cde 100644 --- a/src/models/profiles/queries.rs +++ b/src/models/profiles/queries.rs @@ -243,6 +243,19 @@ pub async fn delete_profile( ", &[&profile_id], ).await?; + transaction.execute( + " + UPDATE post + SET reply_count = reply_count - reply.count + FROM ( + SELECT in_reply_to_id, count(*) FROM post + WHERE author_id = $1 AND in_reply_to_id IS NOT NULL + GROUP BY in_reply_to_id + ) AS reply + WHERE post.id = reply.in_reply_to_id + ", + &[&profile_id], + ).await?; // Delete profile let deleted_count = transaction.execute( "