Make WordPress Core

Opened 4 years ago

Last modified 4 days ago

#19372 assigned enhancement

Don't call wp_count_comments() when we don't need to

Reported by: johnbillion Owned by: wonderboymusic
Milestone: 4.4 Priority: normal
Severity: minor Version: 3.2
Component: Comments Keywords: needs-patch
Focuses: performance Cc:


Comments get counted on every admin screen with wp_count_comments(). We can skip a database call by not counting them if the user doesn't have the edit_posts capability.

Side note: With a persistent object cache it's possible to have admin screens with zero database queries with this patch applied. As an exercise you could write a database class that lazy loads MySQL and you'll get an admin screen that doesn't load MySQL. Almost completely pointless, but interesting nonetheless.

Attachments (1)

19372.patch (753 bytes) - added by johnbillion 4 years ago.

Download all attachments as: .zip

Change History (9)

@johnbillion4 years ago

comment:1 @johnbillion4 years ago

  • Keywords has-patch added


comment:2 @scribu4 years ago

I think 'moderate_comments' would be a more appropriate capability to check. Related: #12104

comment:3 @ocean903 years ago

Related: #11409

Version 0, edited 3 years ago by ocean90 (next)

comment:4 @nacin21 months ago

  • Component changed from Performance to Comments
  • Focuses performance added

comment:5 @johnbillion5 months ago

#32366 was marked as a duplicate.

comment:6 @justindocanto5 months ago

The proposed solution here does not fix what I mentioned in #32366.

Yes, both mention that it shouldn't be called when it's not needed, but the scenarios are completely different.

If I'm an admin and can 'edit_posts' Im still going to have the problem mentioned in #32366 because I'm still querying 5,000,000 comments on every single page load.

I think this ticket needs a better way to disable the function from being called OR we leave my ticket open and create another solution for the problem I brought up since this solution does not address it.

comment:7 @wonderboymusic10 days ago

  • Keywords needs-patch added; has-patch removed
  • Milestone changed from Awaiting Review to 4.4

@justindocanto - this ticket suffices. We are attacking comments hard this release, will look at your issue with this one.

comment:8 @wonderboymusic4 days ago

  • Owner set to wonderboymusic
  • Status changed from new to assigned
Note: See TracTickets for help on using tickets.