WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 16 months ago

#18968 closed enhancement (fixed)

Remove some term cache misses

Reported by: johnbillion Owned by: wonderboymusic
Milestone: 4.0 Priority: normal
Severity: normal Version: 3.3
Component: Taxonomy Keywords: has-patch
Focuses: performance Cc:

Description

On post listing screens a database query is performed for each taxonomy on each post. We can hit the term cache instead by using get_the_terms() in place of wp_get_object_terms() and wp_get_post_terms().

By default, this change won't impact performance because the term cache isn't primed at this point, but on a site using a persistent object cache it'll hit the term cache each time instead of performing a database query. This saves {numberofposts} × {numberoftaxonomies} queries which can be quite a few on custom post type screens which display several taxonomy columns.

Attachments (3)

18968.patch (1.5 KB) - added by johnbillion 4 years ago.
18968-r25222.patch (1.4 KB) - added by jeffstieler 2 years ago.
18968.diff (2.7 KB) - added by wonderboymusic 16 months ago.

Download all attachments as: .zip

Change History (12)

@johnbillion4 years ago

comment:1 @johnbillion4 years ago

  • Keywords has-patch added

Patch.

comment:2 @scribu4 years ago

I don't think using get_the_terms() in get_terms_to_edit() is a good idea.

Checking the cache directly in get_terms_to_edit() maybe, although it probably won't help much.

comment:3 @nacin4 years ago

I don't know if using get_the_terms() here is a bad idea. While it is a front-end template tag, we already use get_the_tags() and get_the_category() in the list tables.

That said, if it's decided we don't do this, then we should be checking get_object_term_cache() before hitting wp_get_post_terms().

comment:4 @c3mdigital2 years ago

  • Keywords needs-refresh added

@jeffstieler2 years ago

comment:5 @jeffstieler2 years ago

  • Cc jeff@… added
  • Keywords needs-refresh removed

Updated the patch against r25222 so it can be tested again.

comment:6 @nacin20 months ago

  • Component changed from Performance to Taxonomy
  • Focuses performance added

comment:7 @wonderboymusic17 months ago

  • Milestone changed from Awaiting Review to 4.0

This is patched and can be investigated for inclusion in our 4.0 Taxonomy work

comment:8 @wonderboymusic16 months ago

*Testing of Posts list table:*

Without patch, non-persistent:
DB: 61
CACHE: 1621

Without patch, with Memcached:
DB: 49
CACHE: 1602

With patch, non-persistent:

DB: 21
CACHE: 1701

With patch, with Memcached:
DB: 9
CACHE: 1682

*With the check for cache in get_terms_to_edit():*

non-persistent:
DB: 41
CACHE: 1641

with Memcached:
DB: 29
CACHE: 1622

*An alternate approach in get_terms_to_edit() - basically the
get_the_terms() cache logic that doesn't hit a filter:*

non-persistent:
DB: 21
CACHE: 1681

with Memcached:
DB: 9
CACHE: 1662

Ding ding ding!

*Without the call to get_the_terms() for hierarchical*

Non-persistent:
DB: 41
CACHE: 1641

Memcached:
DB: 29
CACHE: 1622

@wonderboymusic16 months ago

comment:9 @wonderboymusic16 months ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 28561:

In get_terms_to_edit(), call get_object_term_cache() before priming cache with wp_get_object_terms().

In get_inline_data(), do the same.

On list table screens with taxonomies in the admin, this dramatically reduces the number of database queries (3x less). Even more so with a persistent object cache (5x less).

Props johnbillion, jeffstieler, wonderboymusic.
Fixes #18968.

Note: See TracTickets for help on using tickets.