Make WordPress Core

Opened 4 weeks ago

Closed 18 hours ago

Last modified 4 hours ago

#61484 closed enhancement (fixed)

Prime notoptions within `delete_option()`, `delete_network_option()`.

Reported by: peterwilsoncc's profile peterwilsoncc Owned by: pbearne's profile pbearne
Milestone: 6.7 Priority: normal
Severity: normal Version:
Component: Options, Meta APIs Keywords: has-patch has-unit-tests
Focuses: performance Cc:

Description

When an option is deleted from the database, it becomes known that the option does not exist. However, the notoptions cache is not primed to include this information.

The result is that a subsequent call to get the option will query the database unnecessarily. Priming the notoptions cache in this instance will prevent these queries.

$ wp shell 
wp> update_option( 'delete_option_testing', 'yes' );
=> bool(true)
wp> get_num_queries();
=> int(42)
wp> get_option( 'delete_option_testing' ); 
=> string(3) "yes"
wp> get_num_queries();
=> int(42)
wp> delete_option( 'delete_option_testing' );
=> bool(true)
wp> get_num_queries();
=> int(45)
wp> get_option( 'delete_option_testing' );
=> bool(false)
wp> get_num_queries();
=> int(46)

Change History (11)

This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.


3 weeks ago

#2 @pbearne
3 weeks ago

  • Owner set to pbearne
  • Status changed from new to assigned

#3 @mukesh27
3 weeks ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 6.7

This ticket was mentioned in PR #6964 on WordPress/wordpress-develop by @pbearne.


3 weeks ago
#4

  • Keywords has-patch has-unit-tests added; needs-patch removed

Update delete_option to modify notoptions cache

This commit introduces updates to the delete_option and delete_network_option functions so that they modify the notoptions cache. Corresponding unit tests have been added to ensure the behavior is as expected. This ensures the query count doesn't increase when calling get_option or get_network_option after an option has been deleted.

@peterwilsoncc commented on PR #6964:


3 weeks ago
#5

@pbearne Are you able to make the same changes to the network options code?

@pbearne commented on PR #6964:


2 weeks ago
#6

@pbearne Are you able to make the same changes to the network options code?

added to delete_network_option to we need it elsewhere?

@peterwilsoncc commented on PR #6964:


2 weeks ago
#7

I mean the changes I suggested in the original review. I made them against the options functions and tests but they're also needed for the network options.

@pbearne commented on PR #6964:


7 days ago
#8

@peterwilsoncc made the changes

#9 @peterwilsoncc
18 hours ago

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

In 58782:

Options, Meta APIs: Prime notoptions cache when deleting options.

Prime the notoptions cache within delete_option and delete_network_option to avoid the need for a database query if get_option or get_network_option is subsequently called.

Adds some associated tests to ensure that an option is cleared from the notoptions cache when an option is added either via add_option, update_option or their network option equivalent.

Props pbearne, mukesh27.
Fixes #61484.

Note: See TracTickets for help on using tickets.