WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#11409 closed enhancement (wontfix)

wp_count_comments() should be cached in a transient.

Reported by: Denis-de-Bernardy Owned by: ryan
Milestone: Priority: normal
Severity: normal Version:
Component: Optimization Keywords: needs-patch
Focuses: Cc:

Description

wp_count_comments() gets called on every admin page. It's not a super expensive on, but it probably belongs in a transient that gets updated whenever the number of pending comment changes.

Attachments (1)

11409.diff (585 bytes) - added by chrisscott 4 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 Denis-de-Bernardy4 years ago

  • Component changed from Cache to Optimization

comment:2 Denis-de-Bernardy4 years ago

  • Keywords needs-patch 2nd-opinion added

comment:3 hakre4 years ago

Nice find, this is for the menu. Maybe we should cache the number of plugins as well or isn't that already chached, right?

comment:4 Denis-de-Bernardy4 years ago

if you're meaning plugin updates, those are already cached.

comment:5 nacin4 years ago

  • Keywords 2nd-opinion removed

chrisscott4 years ago

comment:6 chrisscott4 years ago

  • Keywords has-patch added; needs-patch removed

Patch attached against r13330 to change wp_cache_get/set to transient.

comment:7 follow-up: nacin4 years ago

  • Keywords needs-patch added; has-patch removed

We'd also need to update/clear the transient whenever the number of pending comments changes.

comment:8 in reply to: ↑ 7 ; follow-up: chrisscott4 years ago

Replying to nacin:

We'd also need to update/clear the transient whenever the number of pending comments changes.

Sorry, I thought about that and then forgot just as quickly...

This is a little more complex than just pending comment change since the object stored in the transient has counts for total_comments, approved, moderated, spam, trash and post-trash statuses. Not sure how to proceed w/this.

comment:9 in reply to: ↑ 8 nacin4 years ago

Replying to chrisscott:

Replying to nacin:

We'd also need to update/clear the transient whenever the number of pending comments changes.

This is a little more complex than just pending comment change since the object stored in the transient has counts for total_comments, approved, moderated, spam, trash and post-trash statuses. Not sure how to proceed w/this.

We can bust the transient during a comment status change.

comment:10 Denis-de-Bernardy4 years ago

  • Resolution set to wontfix
  • Status changed from new to closed

per discussion on IRC, it's not persistently cached because on sites that get loads of comments, it gets invalidated all the time.

comment:11 nacin4 years ago

  • Milestone 3.0 deleted
Note: See TracTickets for help on using tickets.