[wp-trac] [WordPress Trac] #36251: Allowed memory size exhausted on wp_update_term

WordPress Trac noreply at wordpress.org
Wed May 4 04:55:51 UTC 2016


#36251: Allowed memory size exhausted on wp_update_term
-----------------------------+--------------------------
 Reporter:  rahal.aboulfeth  |       Owner:
     Type:  defect (bug)     |      Status:  new
 Priority:  normal           |   Milestone:  4.6
Component:  Taxonomy         |     Version:  3.9
 Severity:  normal           |  Resolution:
 Keywords:                   |     Focuses:  performance
-----------------------------+--------------------------
Changes (by boonebgorges):

 * milestone:  Future Release => 4.6


Comment:

 [attachment:36251.diff] is a first attempt at fixing the problem. Notes:

 - Anywhere where the `{$taxonomy}_relationships` cache is set, use an
 array of term IDs rather than full term data.
 - When term data is pulled from the cache (`get_object_term_cache()`),
 convert term IDs to term data arrays. There is a bit of juggling involved.
 `wp_cache_get()` gives `[1, 2, 3]`. In order to get terms 1, 2, and 3 from
 the cache, we use `get_term( 1 )` etc, which returns a `WP_Term` object.
 But functions calling `get_object_term_cache()` expect an array rather
 than `WP_Term`, so we return the `$data` property from the term objects,
 and let the functions that call `get_object_term_cache()` convert those
 arrays back into `WP_Term` objects. It's a bit clunky, but required for
 backward compatibility.
 - Some unit tests are no longer relevant, so they've been updated for the
 new technique.

 This seems to me a much improved strategy over what's currently in place.
 By reducing redundancy in the term data we cache (since things like
 `name`, etc are only cached with the individual object), we reduce the
 size of the cache, and fix bugs like #22526 along the way.

 The one remaining compatibility issue I can think of is that there may be
 plugins calling `wp_cache_set( $object_id, "{$taxonomy}_relationships" )`
 directly, rather than `update_object_term_cache()`. If plugins manually
 put term arrays rather than term IDs into the cache, things will break.
 Generally, we don't go out of our way to maintain backward compatibility
 with the structure of the data we keep in our internal caches, so maybe
 this is not a concern. If it is, `get_object_term_cache()` could include a
 check to see whether the cached data is in the legacy format, and convert
 as necessary.

 Feedback welcome.

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


More information about the wp-trac mailing list