Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#52549 closed defect (bug) (fixed)

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

Reported by: dd32's profile dd32 Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.7 Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: has-patch
Focuses: Cc:

Description

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

The attached PR optimises wp_delete_term() slightly to simply call wp_remove_object_terms() when no default term is required, skipping the terms fetch/diff step which can significantly speed up the deletion process.

This was encountered on WordPress.org Support Forums while trying to remove a topic tag with 10,000+ threads, at that scale the fetch/diff process was much slower than simply removing the term.

Change History (4)

This ticket was mentioned in PR #1011 on WordPress/wordpress-develop by dd32.


4 years ago
#1

  • Keywords has-patch added

When no default term exists for a taxonomy and we're deleting a term, skip fetch/diff/set, just remove the term directly from all objects.

Trac ticket: https://core.trac.wordpress.org/ticket/52549

#2 @SergeyBiryukov
4 years ago

  • Milestone changed from Awaiting Review to 5.7
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#3 @SergeyBiryukov
4 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 50389:

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.

Note: See TracTickets for help on using tickets.