Make WordPress Core

Opened 2 years ago

Closed 17 months ago

Last modified 17 months ago

#54472 closed defect (bug) (fixed)

Taxonomy: Unregistering taxonomy with default term endlessly regenerates options

Reported by: dlh's profile dlh Owned by: peterwilsoncc's profile peterwilsoncc
Milestone: 6.1 Priority: normal
Severity: normal Version: 5.5
Component: Taxonomy Keywords: has-patch commit needs-dev-note
Focuses: performance Cc:

Description

[48480] added logic to unregister_taxonomy() to delete the default term option for the taxonomy if it had a default term. This logic causes the default term option for the taxonomy to be created and then deleted on every request: created when the taxonomy is registered, deleted when the taxonomy is unregistered, created again in the next request because it was deleted in the previous request, and so on.

Since taxonomies are registered at runtime and can't be unregistered unless they're already registered, the option will necessarily be created and deleted within the same request and again on every subsequent request, as opposed to a one-time operation like plugin deactivation.

I can sympathize with the desire to "clean up" the database as part of unregistering the taxonomy, but the cost to performance seems unnecessarily high in this case. There's also precedent: the {$taxonomy}_children option isn't deleted when the taxonomy is unregistered, either.

Accordingly, the linked Pull Request would remove the delete_option() call from unregister_taxonomy().

Change History (10)

#2 @SergeyBiryukov
2 years ago

  • Milestone changed from Awaiting Review to 5.9

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


2 years ago

#4 @audrasjb
2 years ago

  • Milestone changed from 5.9 to 6.0

Moving this ticket to 6.0 as we're releasing WP 5.9 beta 1.

This ticket was mentioned in Slack in #core by costdev. View the logs.


20 months ago

#6 @costdev
20 months ago

  • Keywords needs-testing added

#7 @costdev
19 months ago

  • Milestone changed from 6.0 to 6.1

With 6.0 RC1 starting soon, I'm moving this to the 6.1 milestone.

#8 @peterwilsoncc
17 months ago

  • Keywords commit needs-dev-note added; needs-testing removed

I've tested this with a mini plugin that registers and then unregisters a taxonomy with a default term.

Trunk

Each and every page load includes the following database queries:

INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`)
VALUES ('default_term_pwcc_test_taxonomy', '19', 'yes')
ON DUPLICATE KEY
UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`);

DELETE
FROM `wp_options`
WHERE `option_name` = 'default_term_pwcc_test_taxonomy';

With the patch applied

The FIRST request adds the default option to the database as the taxonomy is registered:

INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`)
VALUES ('default_term_pwcc_test_taxonomy', '19', 'yes')
ON DUPLICATE KEY
UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`);

The SECOND and subsequent requests make no changes to the database.

#9 @peterwilsoncc
17 months ago

  • Owner set to peterwilsoncc
  • Resolution set to fixed
  • Status changed from new to closed

In 53669:

Taxonomy: Retain default term option when unregistering taxos.

No longer delete the default term option in unregister_taxonomy() to improve database performance.

Since taxonomies are registered at runtime and can't be unregistered unless they're already registered, prior to this
change the option was created and deleted on each request.

Deleting the option should occur on a one-time opperation such as plugin deactivation.

Follow up to [48480].

Props dlh.
Fixes #54472.

peterwilsoncc commented on PR #1916:


17 months ago
#10

Committed in 5b5c74b904757afb9fe0a03b0a37d2e8bd127db4 (canonically https://core.trac.wordpress.org/changeset/53669)

Note: See TracTickets for help on using tickets.