Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#19708 closed defect (bug) (fixed)

get_post_custom returns no data when cache addition suspended

Reported by: leewillis77 Owned by: duck_
Priority: normal Milestone: 3.4
Component: General Version: 3.3
Severity: normal Keywords: has-patch
Cc: Focuses:

Description

If cache addition is suspended via wp_suspend_cache_addition(true) then get_post_custom($foo) returns no data.

The cause is that in optimising for performance inside get_post_custom an assumption that cache values can be stored and subsequently retrieved. As a result, the return value is generated by calling wp_cache_get() which will fail to return anything since cache additions are suspended.

The values required are however already being generated and passed back into get_post_custom. The attached patch returns these without relying on a call to wp_cache_get.

Attachments (3)

19708.diff​ (1.2 KB ) - added by leewillis77 15 years ago.
Proposed patch
19708-2.diff​ (1.2 KB ) - added by leewillis77 15 years ago.
Revised patch attached - correctly deals with a false returned from update_postmeta_cache().
19708.3.diff​ (1.1 KB ) - added by duck_ 15 years ago.

Download all attachments as: .zip

Change History (11)

@leewillis77
15 years ago

Proposed patch

@leewillis77
15 years ago

Revised patch attached - correctly deals with a false returned from update_postmeta_cache().

#1 @leewillis77
15 years ago

  • Keywords has-patch added

#2 @ryan
15 years ago

  • Milestone Awaiting Review → 3.4

This could also be a problem during imports.

#3 @leewillis77
15 years ago

As with #19690, the use case that caused me to stumble on this is in plugins that wish to iterate over all (or a potentially large number of) posts. The specific use case that caused this is generating an XML feed of product information from e-Commerce stores for Google Merchant Centre.

In this context you want to iterate over all posts of a specific type, but there's no specific advantage in adding those posts (Or related information) to the cache - hence the use of wp_suspend_cache_addition(true).

Unfortunately as soon as cache additions are suspended, get_post_custom fails to return data for posts that do have custom info set.

@duck_
15 years ago

#4 @duck_
15 years ago

Nice catch.

I have attached 19708.3.diff​ which also simplifies get_post_custom() by essentially making it a wrapper for get_post_meta() with $meta_key set to ''.

#5 @leewillis77
15 years ago

Looks good, and works for me ...

Thanks

#6 @duck_
15 years ago

  • Owner set to duck_
  • Resolution → fixed
  • Status new → closed

In [19906]:

Make get_post_custom() a wrapper of get_post_meta() so that it works when cache addition is suspended and to simplify it.

Props leewillis77 for the initial patch. Fixes #19708.

#7 @scribu
15 years ago

3 birds with one stone: #15483 #18702

#8 @scribu
15 years ago

Related: #19882

Note: See TracTickets for help on using tickets.