Ticket #2836 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

wp_delete_comment() uses simple comment count decrementation instead of getting a fresh count

Reported by: markjaquith Assigned to: markjaquith
Priority: normal Milestone:
Component: General Version: 2.0.3
Severity: normal Keywords: has-patch
Cc:

Description

wp_delete_comment() decrements the comment count for its parent post by subtracting 1 from the current count. This perpetuates errors created by older plugins. It also doesn't jive with comment creation, in which a fresh count is made.

Maybe in a year or two, after plugins have been all updated to use the API functions, we can go back to simple incrementation/decrementation (which is faster, and saves a query), but for now, we should try to minimize comment count errors and do a fresh count on every change.

I'll be uploading patches for trunk and the 2.0 branch shortly.

Attachments

delete_comment_redo_count_BRANCHES_2.0.diff (0.8 kB) - added by markjaquith on 06/18/06 11:59:16.
patch for /branches/2.0/
delete_comment_redo_count_TRUNK.diff (1.9 kB) - added by markjaquith on 06/18/06 11:59:44.
patch for /trunk/

Change History

06/18/06 11:59:16 changed by markjaquith

  • attachment delete_comment_redo_count_BRANCHES_2.0.diff added.

patch for /branches/2.0/

06/18/06 11:59:44 changed by markjaquith

  • attachment delete_comment_redo_count_TRUNK.diff added.

patch for /trunk/

06/18/06 12:04:05 changed by markjaquith

  • keywords set to has-patch.
  • status changed from new to assigned.

The patch for the 2.0 branch is simple: instead of blindly decrementing, it does a fresh count, identical to the way it does in wp_insert_comment()

The patch for Trunk is a little more comprehensive. I wrote a new function, wp_update_comment_count() which takes a post ID and does the COUNT() and the UPDATE queries, as well as filling in an entry for the comment count cache array. wp_insert_comment(), wp_delete_comment() and wp_update_comment() have all been edited to use this function.

06/19/06 17:17:53 changed by ryan

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [3887]) wp_update_comment_count() from MarkJaquith?. fixes #2836

06/19/06 17:18:21 changed by ryan

(In [3888]) wp_update_comment_count() from MarkJaquith?. fixes #2836

06/19/06 17:18:47 changed by ryan

  • milestone changed from 2.1 to 2.0.4.

11/30/06 19:41:50 changed by

  • milestone deleted.

Milestone 2.0.4 deleted