[wp-trac] [WordPress Trac] #24386: Make _pad_term_counts work for non-post type objects and attachments

WordPress Trac noreply at wordpress.org
Thu Nov 5 15:55:22 UTC 2020


#24386: Make _pad_term_counts work for non-post type objects and attachments
------------------------------------------+---------------------
 Reporter:  TomAuger                      |       Owner:  (none)
     Type:  enhancement                   |      Status:  new
 Priority:  normal                        |   Milestone:
Component:  Taxonomy                      |     Version:
 Severity:  normal                        |  Resolution:
 Keywords:  needs-patch needs-unit-tests  |     Focuses:
------------------------------------------+---------------------

Comment (by david.binda):

 With #40351 being worked on, I wonder if it's a good time to revisit this
 ticket.

 > I think I agree that we should be using $term->count, and not doing a
 separate database query. I'm not sure why the query was ever necessary;

 Reviewing the revisions mentioned above, as well as current usage of the
 `pad_counts` argument of the `get_terms` function, I don't believe that
 the database query is meant for accuracy of the numbers displayed.

 The `_pad_term_counts` function is only called in case the `pad_counts`
 arg is explicitly set to `true` (it default to `false`). Disregarding the
 current implementation, which recalculates the counts from scratch, I'd
 say the `_pad_term_counts` function is only really meant for count padding
 in hierarchical display, so the parent term count contains numbers for all
 it's children, not for ensuring the accuracy of the numbers, especially as
 there is no such accuracy check performed when the `pad_counts` arg is set
 to `false` (default behaviour).


 > The key will be to write some unit tests that verify that the 'count'
 field is correctly recalculated on 'transition_post_status'.

 Those seem to be worked on in terms of r49141 (yet currently reverted).

 From my point of view, it makes sense to move towards a solution which
 takes advantage of the `$term->count` value for calculating the padding of
 ancestor terms, as it would significantly increase the performance of the
 function in terms of reducing SQL queries as well as lowering the memory
 usage.

 I have attempted to implement `$term->count` approach by modifying the
 `Walker` class to start with some solid and tested implementation ( see
 the attached diff ).

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


More information about the wp-trac mailing list