[wp-trac] [WordPress Trac] #58490: Make wp_update_term_count function site context aware for the multisite
WordPress Trac
noreply at wordpress.org
Thu Jun 8 12:32:40 UTC 2023
#58490: Make wp_update_term_count function site context aware for the multisite
--------------------------+-----------------------------
Reporter: sathyapulse | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
During the import process, a performance problem arose because of term
counting with each insert. However, this issue was reported and resolved
with ticket #5377. Unfortunately, the solution is not compatible with
multisite.
The syndication plugin causes delays in the syndication of multiple posts
between sites in the multisite, primarily because of the term counting
required during each insert.
Suppose you need to synchronise content across subsites and want to
enhance the sync performance by turning off the term counting logic. In
that case, you would follow these steps.
{{{
$post_list = [1, 2, 3];
switch_to_blog(2);
wp_defer_term_counting(true);
do_multiple_syncs( $post_list );
wp_defer_term_counting(false);
restore_current_blog();
}}}
We made a change by disabling term counting during each insertion and
performing it after the inserts, as planned. However, this caused some
problems. The menus on our website kept disappearing without any apparent
reason, and we had to resave them to restore them manually.
Upon inspection, it was discovered that the `wp_update_term_count`
function does not consider the multisite when the term counting is
disabled [https://github.com/WordPress/wordpress-develop/blob/6.2/src/wp-
includes/taxonomy.php#L3464]. For instance, in the sync job mentioned
above, if the list of term IDs from subsite 2 is added for a recount in a
static variable, the function incorrectly recounts it in the main site.
The term count was updated to `0` in the database. This is because the
term ID doesn't exist on the main site or no posts have been assigned. It
causes the check (https://github.com/WordPress/wordpress-
develop/blob/6.2/src/wp-includes/nav-menu.php#L721-L725) to fail on the
`wp_get_nav_menu_items` function and menus disappear.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58490>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list