[wp-trac] [WordPress Trac] #38280: Make term count for a specific object type available
WordPress Trac
noreply at wordpress.org
Fri Feb 17 03:28:38 UTC 2017
#38280: Make term count for a specific object type available
--------------------------------------+------------------------------
Reporter: desrosj | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 4.7
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests | Focuses:
--------------------------------------+------------------------------
Comment (by boonebgorges):
@desrosj Nice job on this patch so far.
The comment `// When a count for an object type does not exist, if any
other meta caches exist we can assume 0.` makes me nervous. I guess this
is because you're not storing 0s, and the presence a count for another
object type means that WP has recently done a relevant count. I worry that
this is going to be subject to weird race conditions or data integrity
problems. (For example: what if a taxonomy originally assigned to 'post'
becomes assigned to `array( 'post', 'page' )`?) How about some combination
of your original array-based approach and the one-entry-per-object-type
approach? There'd be a single key containing a list of the object types
for which a count exists, but the counts themselves would be stored in
their own rows. This way, if `$type` appears in the array, and if
`get_term_meta( $term_id, '_wp_object_count_' . $type, true )` returned
false for a `$type`, we can be confident that `$type` has indeed been
counted.
> Bullet point one made me think of a couple scenarios that could result
in some abandoned meta caches
These situations are rare enough that I wouldn't worry about it too much.
As a precaution, `_update_post_term_count()` could `delete_post_meta()`
for all of a post's existing counts before generating and saving new ones
(another argument for having a separate list of the object types that have
been counted). This way, the stale data will be removed during the next
count.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38280#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list