Make WordPress Core

Opened 17 months ago

Closed 14 months ago

Last modified 11 months ago

#57645 closed enhancement (fixed)

Implement lazy loading term meta in WP_Term_Query

Reported by: spacedmonkey's profile spacedmonkey Owned by: spacedmonkey's profile spacedmonkey
Milestone: 6.3 Priority: normal
Severity: normal Version: 4.4
Component: Taxonomy Keywords: has-patch has-unit-tests has-dev-note
Focuses: performance Cc:

Description

When using WP_Term_Query class, term meta should be lazily loaded, as term meta is not required for most page loads. Term meta can easily be lazily load using existing apis found in core in the WP_Metadata_Lazyloader class.

Change History (11)

This ticket was mentioned in PR #4010 on WordPress/wordpress-develop by @spacedmonkey.


17 months ago
#1

  • Keywords has-patch added

This ticket was mentioned in PR #4153 on WordPress/wordpress-develop by @spacedmonkey.


16 months ago
#2

Make it so that term meta is always lazy loaded.

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

#3 @spacedmonkey
15 months ago

  • Keywords has-unit-tests added
  • Milestone changed from Future Release to 6.3

#4 @peterwilsoncc
15 months ago

I think this is a good idea.

As some idle pondering rather than a passive aggressive change request.

Would it be better to introduce an additional attribute to term queries, lazy_load_term_meta with the default value true?

If for some reason, a developer wishes to group the database queries to run all at once per the current set up, they could set the value to false.

#5 @spacedmonkey
15 months ago

Would it be better to introduce an additional attribute to term queries, lazy_load_term_meta with the default value true?

I did consider this, but the problem is that many developers do not use update_term_meta_cache as is. Term meta is being loaded when it should not be. There are even places in core like #57701 where it is being loaded.

I think that we should be aggressive in caching term meta, as looking at the plugin repo, it is not heavily used.

Whatever is decided, we should do the same here #57801.

@spacedmonkey commented on PR #4153:


14 months ago
#6

Do you mind taking a look at this @peterwilsoncc ?

#7 @spacedmonkey
14 months ago

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

In 55671:

Taxonomy: Always lazily load term meta.

In [34529] introduced lazy loading of term meta. However, this was only in the context of WP_Query. Other parts of the codebase, like WP_Term_Query did not lazily load term meta. In this change, calls to update_termmeta_cache are now replaced with wp_lazyload_term_meta, that instead of priming term meta caches, just adds them to the queue to be primed it ever called. This results in far less database queries, as there a number of places where term meta is being primed unnecessarily and never used. Adding everything to the term meta queue, also means that if term meta is used, that is all loaded in a single database / cache call.

Props spacedmonkey, mukesh27, peterwilsoncc.
Fixes #57645.

@spacedmonkey commented on PR #4010:


14 months ago
#8

Committed in 55671

@spacedmonkey commented on PR #4153:


14 months ago
#9

Committed in 55671.

#10 @spacedmonkey
12 months ago

  • Keywords needs-dev-note added
Note: See TracTickets for help on using tickets.