Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#43142 closed enhancement (fixed)

Do not warm term meta cache unnecessarily

Reported by: peterwilsoncc's profile peterwilsoncc Owned by: peterwilsoncc's profile peterwilsoncc
Milestone: 5.1 Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: has-patch
Focuses: performance Cc:

Description (last modified by peterwilsoncc)

A number of core functions calls to get_terms() warm the term meta cache unnecessarily. Most notably, _get_term_hierarchy() warms the term meta cache for all of a taxonomy's terms.

Attachments (4)

43142.diff (603 bytes) - added by peterwilsoncc 7 years ago.
43142.2.diff (2.4 KB) - added by peterwilsoncc 7 years ago.
43142.3.diff (2.4 KB) - added by boonebgorges 7 years ago.
43142.4.diff (2.4 KB) - added by peterwilsoncc 7 years ago.

Download all attachments as: .zip

Change History (14)

@peterwilsoncc
7 years ago

#1 @boonebgorges
7 years ago

  • Keywords commit added

+1

#2 @peterwilsoncc
7 years ago

I noticed a few places in the wp_(insert|update)_term() workflow where the meta cache may be getting warmed unnecessarily, I'll do a further review and make this ticket generic if needs be.

#3 @peterwilsoncc
7 years ago

  • Description modified (diff)
  • Summary changed from Do not warm term meta cache in `_get_term_hierarchy` to Do not warm term meta cache unnecessarily

#4 @peterwilsoncc
7 years ago

  • Keywords commit removed

Commit keyword removed as it applies to the previous patch.

43142.2.diff removes term caching from several instances in src/wp-includes/taxonomy.php:

  • wp_insert_term(): search for siblings with the same name
  • wp_insert_term(): search for all siblings
  • wp_set_object_terms(): search for old tt_ids using wp_get_object_terms()
  • wp_set_object_terms(): search for final tt_ids using wp_get_object_terms()
  • _get_term_hierarchy(): hierarchy update as in previous patch

@boonebgorges would you mind taking another look at the new patch? It's the calls setting an objects terms that I am least sure about.

@boonebgorges
7 years ago

#5 @boonebgorges
7 years ago

Thanks for taking a closer look, @peterwilsoncc. The functional changes look good to me.

43142.3.diff includes two coding standards changes:

  1. No spaces in $args['parent']
  2. You broke each argument for wp_get_object_terms() into its own line. This is not a strict violation of the coding standards, but I haven't seen this specific function use this formatting before. I changed it to what I see as the more common format. But maybe this could use advice from @jrf. (See right-hand 2460 in 43142.3.diff and 43142.2.diff )

#6 @jrf
7 years ago

You broke each argument for wp_get_object_terms() into its own line. This is not a strict violation of the coding standards, but I haven't seen this specific function use this formatting before. I changed it to what I see as the more common format. But maybe this could use advice from @jrf. (See right-hand 2460 in 43142.3.diff​ and 43142.2.diff​ )

@boonebgorges Thanks for the ping. I've just had a quick look and the function layout in 43142.2.diff is correct.

The rules which come into play here are:

  1. For multi-item associative arrays, each array item should start on their own line.
  2. For multi-line function calls, each parameter should start on their own line.

These rules have been correctly applied in the patch 2. In the patch 3, the second rule is disregarded.

Hope this helps ;-)

#7 @boonebgorges
7 years ago

@jrf Thanks for chiming in. Could you point me toward where the following rule is codified, either in WPCS or in the documentation? (Mainly so I don't have to bug you in the future.) I ran what I thought was the most recent WordPress-Core standards against both 2 and 3 and didn't see a notice either way, but it's likely I was doing something wrong.

For multi-line function calls, each parameter should start on their own line.

#8 @peterwilsoncc
7 years ago

  • Owner set to peterwilsoncc
  • Status changed from new to assigned

In 43142.4.diff, coding standards!

It's 43142.2.diff with spacing fixed for $args['parent'] following the feedback above. Ta.

#9 @peterwilsoncc
7 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 42649:

Taxonomy: Stop warming term meta cache unnecessarily.

Prevent several core function calls to get_terms() from warming the term meta cache.

Props peterwilsoncc, boonebgorges, jrf.
Fixes #43142.

#10 @johnbillion
6 years ago

  • Milestone changed from 5.0 to 5.1
Note: See TracTickets for help on using tickets.