Make WordPress Core

Opened 5 months ago

Last modified 4 months ago

#63945 new enhancement

Make cache in wp_count_posts persistent

Reported by: spacedmonkey's profile spacedmonkey Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 2.5
Component: Administration Keywords: has-patch
Focuses: performance Cc:

Description

Current there is a cache in wp_count_posts function. See

        $cache_key = _count_posts_cache_key( $type, $perm );

        $counts = wp_cache_get( $cache_key, 'counts' );

As this use the counts cache group, this cache does not persistent between page requests. However the SQL query that is run in this function, can take a long time and can result in the admin list page to render slowly. This cache should be made to persistent.

Attachments (1)

screenshot.jpg (26.2 KB) - added by spacedmonkey 5 months ago.

Download all attachments as: .zip

Change History (7)

#1 @spacedmonkey
5 months ago

  • Summary changed from Make cache in wp_count_posts to Make cache in wp_count_posts persistent

This ticket was mentioned in PR #9793 on WordPress/wordpress-develop by jonnynews.


5 months ago
#2

  • Keywords has-patch added

Make cache in wp_count_posts & wp_count_attachments persistent, by changing cache groups to post-queries and use the new wp_cache_get_salted and wp_cache_set_salted functions for cache invalidation.

Trac ticket: https://core.trac.wordpress.org/ticket/63945

#3 @spacedmonkey
5 months ago

Love feedback from @dd32, as this is platform level.

This ticket was mentioned in Slack in #core-performance by spacedmonkey. View the logs.


5 months ago

#5 @dd32
5 months ago

See also: #35430 and ticket:47884#comment:8 - I note this seems to be using the route proposed there to allow caching.

I don't have any other feedback, other than that I dislike the query this generates so I'm all for adding caching :D

#6 @umarraza9450
4 months ago

@spacedmonkey Thanks for highlighting this issue.
I’m also experiencing similar slow rendering on large sites due to the non-persistent counts cache.
You can see an example of this behavior on https://nextreport.id

where the admin list page occasionally loads much slower than expected when the SQL query runs.

It would be great if this cache could be made persistent to avoid repeated heavy queries between page requests.

Note: See TracTickets for help on using tickets.