WordPress.org

Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #20635, comment 11


Ignore:
Timestamp:
01/09/2015 07:45:47 PM (5 years ago)
Author:
boonebgorges
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #20635, comment 11

    initial v1  
    88`wp_check_term_hierarchy_for_loops()` is more than we need in this case. (a) It's probably overly expensive to break the hierarchy on a read operation like `get_terms()`, when all we really need here is to ensure that we don't loop infinitely; and (b) there's no need to recurse the hierarchy using `get_term()` (`wp_get_term_taxonomy_parent_id()`) because `_pad_term_counts()` does a single query to grab the whole hierarchy - that is, we already have all the data we need to detect a loop.
    99
    10 I propose that we keep track of already-identified `$ancestors` during the `while` loop, and just break out of it if we detect a loop. Worst case scenario with this fix is that, if the loop comprises only a subset of the terms identified in the `get_terms()` query, it's possible that some terms won't have their counts padded. See [attachment:20635.3.diff] (note that the unit test won't outright fail without the fix, but you'll probably get a maximum execution time fatal error).
     10I propose that we keep track of already-identified `$ancestors` during the `while` loop, and just break out of it if we detect a loop. Worst case scenario with this fix is that, if the loop comprises only a subset of the terms identified in the `get_terms()` query, it's possible that some terms won't have their counts padded. See [attachment:20635.3.2.diff] (note that the unit test won't outright fail without the fix, but you'll probably get a maximum execution time fatal error).