Make WordPress Core

Changeset 50389


Ignore:
Timestamp:
02/19/2021 02:29:29 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Taxonomy: Optimize wp_delete_term() for large object counts without a default term.

When deleting a term, it has to be removed individually from each object it's connected to, which can take some significant time when there are a lot of objects.

By calling wp_remove_object_terms() when no default term is required, we can skip the terms fetch/diff step and significantly speed up the deletion process.

Props dd32.
Fixes #52549.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r50231 r50389  
    19441944
    19451945    foreach ( $object_ids as $object_id ) {
     1946        if ( ! isset( $default ) ) {
     1947            wp_remove_object_terms( $object_id, $term, $taxonomy );
     1948            continue;
     1949        }
     1950
    19461951        $terms = wp_get_object_terms(
    19471952            $object_id,
     
    19521957            )
    19531958        );
     1959
    19541960        if ( 1 === count( $terms ) && isset( $default ) ) {
    19551961            $terms = array( $default );
     
    19601966            }
    19611967        }
     1968
    19621969        $terms = array_map( 'intval', $terms );
    19631970        wp_set_object_terms( $object_id, $terms, $taxonomy );
Note: See TracChangeset for help on using the changeset viewer.