Feature #10788


Main query should be either cached or eliminated on primary site

Added by Boone Gorges about 5 years ago. Updated about 5 years ago.

Priority name:
Category name:
Target version:
Start date:
Due date:
% Done:


Estimated time:
Deployment actions:


The "main query" is uncached. On the Commons main site (id=1), it's sometimes not needed at all (as in the case of the home page). In the vast majority of other cases, it's fetching the 'bp_pages' item; in these cases, we should be caching aggressively. Only rarely do we actually need a database query (as when loading CPTs).

Related issues

Related to CUNY Academic Commons - Feature #10728: Cache primary nav menuResolvedRaymond Hoh2018-11-19

Actions #1

Updated by Boone Gorges about 5 years ago

  • Status changed from New to Resolved
  • Target version changed from 1.15 to 1.14.3

I remembered that Automattic had a plugin that cached those parts of WP_Query that aren't cached by core, so I decided to give it a try.

It does not work out of the box, because of an incompatibility between the function signature of wp_cache_get_multi() as it's defined in our cache drop-in, and the way that advanced-post-cache expects the function to work. I've fixed this in

The plugin is imperfect. Notably, it can't properly cache queries that return empty arrays. This mostly appears to be the fault of WordPress, which doesn't run its found_posts logic (hooked into by advanced-post-cache) when no posts are found. This problem arose specifically in the case of the home page, where WP tries to load the latest non-public posts; since there aren't any, the query was returning an empty result, which was remaining uncached, and thus was being fired on every pageload. As a workaround, I've added a single blank 'post' to the Commons, which allows the plugin to cache the query.

Elsewhere on the main site, the plugin seems to be working as expected. It might be interesting to explore network-activating it, but let's hold off on that for the time being.

It looks at a glance like this plugin ought to eliminate the nav_menu_item queries throughout the main site, but it doesn't. See #10728. This needs investigation.

Down to 3 queries when loading the main page. Would like to get to zero :-D

Actions #2

Updated by Boone Gorges about 5 years ago


Also available in: Atom PDF