Make WordPress Core

Opened 19 years ago

Closed 19 years ago

Last modified 17 months ago

#2836 closed defect (bug) (fixed)

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

Reported by: markjaquith's profile markjaquith Owned by: markjaquith's profile markjaquith
Milestone: Priority: normal
Severity: normal Version: 2.0.3
Component: General Keywords: has-patch
Focuses: 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 (2)

delete_comment_redo_count_BRANCHES_2.0.diff (809 bytes) - added by markjaquith 19 years ago.
patch for /branches/2.0/
delete_comment_redo_count_TRUNK.diff (1.9 KB) - added by markjaquith 19 years ago.
patch for /trunk/

Download all attachments as: .zip

Change History (7)

@markjaquith
19 years ago

patch for /branches/2.0/

@markjaquith
19 years ago

patch for /trunk/

#1 @markjaquith
19 years ago

  • Keywords has-patch added
  • 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.

#2 @ryan
19 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

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

#3 @ryan
19 years ago

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

#4 @ryan
19 years ago

  • Milestone changed from 2.1 to 2.0.4

#5 @(none)
19 years ago

  • Milestone 2.0.4 deleted

Milestone 2.0.4 deleted

Note: See TracTickets for help on using tickets.