[wp-trac] [WordPress Trac] #41796: WP_Term_Query problem using object_ids and number attributes

WordPress Trac noreply at wordpress.org
Fri Sep 15 03:02:40 UTC 2017


#41796: WP_Term_Query problem using object_ids and number attributes
--------------------------+---------------------------
 Reporter:  elvishp2006   |       Owner:  boonebgorges
     Type:  defect (bug)  |      Status:  reopened
 Priority:  normal        |   Milestone:  4.9
Component:  Taxonomy      |     Version:  4.8.1
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |     Focuses:
--------------------------+---------------------------
Changes (by boonebgorges):

 * keywords:  has-patch needs-testing => needs-patch
 * status:  closed => reopened
 * resolution:  fixed =>


Comment:

 Thanks for the note, @Otto42. I knew that it would have performance
 implications, which is why I argued for only using `DISTINCT` when
 absolutely necessary. I hadn't thought of the tag cloud as a place that
 would be affected, but I knew that there would be places affected.

 I see three options:

 1. Leave [41377] in. Other sites will face the same fate as wordpress.org.
 Should probably be avoided.
 2. Revert [41377], and also add a note to the inline docs that says that
 `number` is simply incompatible with `object_ids`. This is weird and
 inconsistent (we *do* add the `DISTINCT` clause for meta queries) but
 would return us to the status quo.
 3. Try to solve this in PHP.

 The last option seems like the best, but it is not straightforward. The
 naive solution: When `number` accompanies `object_ids`, don't add the
 `LIMIT` clause; Fetch all results, and trim down to `number` in PHP. This
 is going to kill sites like wordpress.org in a different way (instead of
 `DISTINCT`, it'll be the 500,000 tags in memory).

 A more complicated PHP solution is to use the `LIMIT` logic, and then to
 detect in PHP when the returned and deduped results are less than
 `number`. If so, recursively requery for `$number -
  count( $results )`. Eg: `number=10`; deduping from `object_ids` gives you
 8; `WP_Term_Query` requeries `number=2&offset=8` and appends the results;
 etc until we have 10. This is likely to be very complicated.

 If anyone has good ideas, please share them. Otherwise I think we might go
 with option 2 (the status quo).

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


More information about the wp-trac mailing list