[wp-trac] [WordPress Trac] #30380: get_transient doesn't check the return of get_option

WordPress Trac noreply at wordpress.org
Fri Feb 13 23:41:49 UTC 2015


#30380: get_transient doesn't check the return of get_option
---------------------------------+--------------------------
 Reporter:  jamesgol             |       Owner:
     Type:  defect (bug)         |      Status:  new
 Priority:  normal               |   Milestone:  4.2
Component:  Options, Meta APIs   |     Version:  2.8
 Severity:  normal               |  Resolution:
 Keywords:  has-patch 4.2-early  |     Focuses:  performance
---------------------------------+--------------------------

Comment (by afercia):

 Replying to [comment:6 ocean90]:
 > The patch makes sense at first glance, but it's worth mentioning that
 `false < time()` is true, means $transient_option will be deleted from the
 database.
 This caused me some headaches while trying to understand why the featured
 posts in Twenty Fourteen were firing lots of queries. They've been someway
 improved since then see #26744. With the old implementation, my scenario
 was:

 No posts match the featured tag, fallback to sticky posts
 the transient, though intended to be autoloaded, didn't exist yet after a
 settings change
 get_transient() will assume: "If option is not in alloptions, it is not
 autoloaded and thus has a timeout"
 it checks if transient is in $alloptions
 it is not so it will be considered a transient with expiration
 get_option() will cache its non-existence in the 'notoptions' cache
 get_option( $transient_timeout ) will return false
 so it will check if ( false < time() ) :) which evaluates true
 WordPress now thinks it has to deal with an expired transient and will try
 to delete it
 finally, will set $value = false and return false

 This caused also a second round of queries due to the '''old'''
 `get_featured_post_ids()` implementation. Have to say I've checked this
 some months ago, not sure about the current behavior but I fear there's
 some failing assumption here that doesn't cover edge cases or bad
 implementations.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30380#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list