Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#13170 closed enhancement (worksforme)

get_term_by() should check object cache

Reported by: scribu's profile scribu Owned by: ryan's profile 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 14 years ago.
get_terms_by.2.diff (4.1 KB) - added by scribu 14 years ago.
introduce wp_cache_get_group()
13170.diff (1.2 KB) - added by ryan 14 years ago.
Slug -> id cache. Untested.

Download all attachments as: .zip

Change History (12)

@scribu
14 years ago

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

#2 @scribu
14 years ago

  • Type changed from defect (bug) to enhancement

#3 @ryan
14 years ago

$wp_object_cache should never be directly referenced.

#4 @ryan
14 years ago

Maybe add a slug cache.

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

@scribu
14 years ago

introduce wp_cache_get_group()

#5 @scribu
14 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()

#6 @ryan
14 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.

@ryan
14 years ago

Slug -> id cache. Untested.

#7 @scribu
14 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()

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

#9 @scribu
13 years ago

Related: #14983

Note: See TracTickets for help on using tickets.