Opened 5 months ago
Closed 4 months ago
#61484 closed enhancement (fixed)
Prime notoptions within `delete_option()`, `delete_network_option()`.
Reported by: | peterwilsoncc | Owned by: | 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 (14)
This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.
5 months ago
This ticket was mentioned in PR #6964 on WordPress/wordpress-develop by @pbearne.
5 months ago
#4
- Keywords has-patch has-unit-tests added; needs-patch removed
@peterwilsoncc commented on PR #6964:
5 months ago
#5
@pbearne Are you able to make the same changes to the network options code?
5 months 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:
5 months 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.
@peterwilsoncc commented on PR #6964:
4 months ago
#10
#12
@
4 months ago
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening this as @bjorsch picked an issue up while working on #61730.
In delete_option()
the notoptions
cache is set regardless of the result of the database query.
If wpdb::delete()
returns false
(database connection error) then it's not known if the option exists or not so the cache should probably not be set so there ought to be a check for that before setting the cache.
If wpdb::delete()
returns 0
the cache can be set as it's known not to be an option as there were no rows to delete.
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.