Skip to content

Commit 241242c

Browse files
authored
Fixed comments deletion counter (#3849)
1 parent 0318eff commit 241242c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

comments/services/common.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,22 @@ def unpin_comment(comment: Comment):
197197

198198
@transaction.atomic
199199
def soft_delete_comment(comment: Comment):
200-
post = comment.on_post
200+
if comment.is_soft_deleted:
201+
return
201202

202-
# Decrement counter during comment deletion
203-
post.snapshots.filter(viewed_at__gte=comment.created_at).update(
204-
comments_count=F("comments_count") - 1
205-
)
203+
post = comment.on_post
206204

207205
comment.is_soft_deleted = True
208206
comment.save(update_fields=["is_soft_deleted"])
209207

210208
post.update_comment_count()
211209

210+
if not comment.is_private:
211+
# Decrement counter during comment deletion
212+
post.snapshots.filter(viewed_at__gte=comment.created_at).update(
213+
comments_count=F("comments_count") - 1
214+
)
215+
212216

213217
def compute_comment_score(
214218
comment_votes: int,

0 commit comments

Comments
 (0)