Opened 5 weeks ago
Last modified 3 weeks ago
#63562 reviewing defect (bug)
Term counts should not be recalculated when a post transitions between statuses that are not counted
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.9 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | needs-unit-tests has-patch |
Focuses: | performance | Cc: |
Description
This is similar to #42522 but subtly different.
When a post transitions from one status to another, term counts for the terms of the post are unnecessarily recalculated even when neither the old status or the new status are statuses which are included when counting terms. An example is when an autosave is first created.
In simpler terms, term counts for a post should only be recalculated when either its old or new status is publish
. It just needs to respect other statuses added via the update_post_term_count_statuses
filter too.
Change History (10)
This ticket was mentioned in PR #8970 on WordPress/wordpress-develop by @hbhalodia.
5 weeks ago
#1
- Keywords has-patch added; needs-patch removed
#2
in reply to:
↑ description
@
5 weeks ago
- Keywords changes-requested added; has-patch removed
It just needs to respect other statuses added via the
update_post_term_count_statuses
filter too.
@hbhalodia I think the 'update_post_term_count_statuses' filter can be used to fetch other statuses as well -
$countable_statuses = apply_filters( 'update_post_term_count_statuses', array( 'publish' ), null ); if ( ! in_array( $new_status, $countable_statuses, true ) && ! in_array( $old_status, $countable_statuses, true ) ) { return; }
@mukesh27 commented on PR #8970:
4 weeks ago
#3
It just needs to respect other statuses added via the
update_post_term_count_statuses
filter too.
The implementation for filter is missing.
@hbhalodia commented on PR #8970:
4 weeks ago
#4
The implementation for filter is missing.
Yes, Thanks for the note, I am adding the implementation for the same.
#5
@
4 weeks ago
Hi @sandeepdahiya, Thanks for the note, Yes I am adding the implementation for the same.
@hbhalodia commented on PR #8970:
4 weeks ago
#6
Hi @mukeshpanchal27, I have implemented the fix to respect the filter, Let me know if that is correct approach or need to update with some other logic.
Thank You,
@mukesh27 commented on PR #8970:
4 weeks ago
#7
Let's add unit tests that validate the updated functionality.
@hbhalodia commented on PR #8970:
4 weeks ago
#8
Hi @mukeshpanchal27,
I reviewed this and looked into how we can accommodate the suggested test. However, it seems that the existing tests already cover the intended functionality:
The tests in this file already handle the scenario: https://github.com/WordPress/wordpress-develop/blob/trunk/tests/phpunit/tests/term/termCounts.php
For example, we've added a check to ensure that if both the old and new statuses are the same, the term count remains unchanged. This specific case is already covered here: https://github.com/WordPress/wordpress-develop/blob/ebace79f789958504e1ec27e6644fac79ebc3ee4/tests/phpunit/tests/term/termCounts.php#L172
The data provider for that test includes conditions where both statuses are the same, which ensures no change in the term count unless one of the statuses is publish.
Additionally, we already have a test for the update_post_term_count_statuses filter, which covers scenarios where a custom status is added:
https://github.com/WordPress/wordpress-develop/blob/ebace79f789958504e1ec27e6644fac79ebc3ee4/tests/phpunit/tests/term/termCounts.php#L242
So I am not sure if we should proceed to add the test, because I do not see any test specific to this function _update_term_count_on_transition_post_status
added earlier as it seems test functionality covered by the mentioned file.
Let me know if we need to add a specific test for this?
Thank You,
Trac ticket: https://core.trac.wordpress.org/ticket/63562
_update_term_count_on_transition_post_status
which is hooked totransition_post_status
action, and added condition to only recalculate when the new status or old status is publish.