WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#13170 closed enhancement (worksforme)

get_term_by() should check object cache

Reported by: scribu Owned by: ryan
Milestone: Priority: normal
Severity: normal Version:
Component: Cache API Keywords: has-patch
Focuses: Cc:

Description

A lot of queries could be saved if get_term_by() would first look in the term cache before calling $wpdb.

Attachments (3)

get_terms_by.diff (2.0 KB) - added by scribu 4 years ago.
get_terms_by.2.diff (4.1 KB) - added by scribu 4 years ago.
introduce wp_cache_get_group()
13170.diff (1.2 KB) - added by ryan 4 years ago.
Slug -> id cache. Untested.

Download all attachments as: .zip

Change History (12)

scribu4 years ago

comment:1 scribu4 years ago

  • Keywords dev-feedback added

I was thinking of adding a get_group() method to WP_Object_Cache, but I don't want to needlessly clone all the objects in the cache.

Anyway, current patch saved around 25% of queries on a complex front page.

comment:2 scribu4 years ago

  • Type changed from defect (bug) to enhancement

comment:3 ryan4 years ago

$wp_object_cache should never be directly referenced.

comment:4 ryan4 years ago

Maybe add a slug cache.

wp_cache_add($term->slug, $term->term_id, "{$taxonomy}_slugs");

scribu4 years ago

introduce wp_cache_get_group()

comment:5 scribu4 years ago

  • Keywords dev-feedback removed
  • Milestone changed from Unassigned to 3.1

In get_terms_by.2.diff: introduce and use wp_cache_get_group()

comment:6 ryan4 years ago

On multisite installs getting a group will return a colossal amount of data. You also can't assume the backend cache will support it. I think the only way we can do this is as we do users, adding a slug to id cache.

ryan4 years ago

Slug -> id cache. Untested.

comment:7 scribu4 years ago

  • Milestone 3.1 deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Yeah, but that wouldn't cover names.

I think I'll just use a wrapper function for get_term_by()

comment:8 scribu4 years ago

Sorry, I keep seeing your comments after I post...

IMO, what would really be needed here is a way to retrieve an object by more than one key.

In the case of the object cache, this would mean storing a reference to the same taxonomy object in multiple groups.

comment:9 scribu3 years ago

Related: #14983

Note: See TracTickets for help on using tickets.