Make WordPress Core

Opened 14 years ago

Closed 11 years ago

#18968 closed enhancement (fixed)

Remove some term cache misses

Reported by: johnbillion's profile johnbillion Owned by: wonderboymusic's profile 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 14 years ago.
18968-r25222.patch (1.4 KB) - added by jeffstieler 12 years ago.
18968.diff (2.7 KB) - added by wonderboymusic 11 years ago.

Download all attachments as: .zip

Change History (12)

@johnbillion
14 years ago

#1 @johnbillion
14 years ago

  • Keywords has-patch added

Patch.

#2 @scribu
14 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.

#3 @nacin
14 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().

#4 @c3mdigital
12 years ago

  • Keywords needs-refresh added

#5 @jeffstieler
12 years ago

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

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

#6 @nacin
11 years ago

  • Component changed from Performance to Taxonomy
  • Focuses performance added

#7 @wonderboymusic
11 years ago

  • Milestone changed from Awaiting Review to 4.0

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

#8 @wonderboymusic
11 years 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

#9 @wonderboymusic
11 years 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.