Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#33292 closed defect (bug) (duplicate)

Never-used widgets generate database queries

Reported by: dlh's profile dlh Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Widgets Keywords: has-patch dev-feedback
Focuses: Cc:


When WP_Widget::_register() runs, it calls WP_Widget::get_settings(), which then calls get_option( $this->option_name ).

By default, widget options are set to autoload, so the get_option() call can fetch the loaded value. But a widget that has never been used doesn't have an option, so get_option() runs all the way through, including the database query.

This can be tested on a fresh install. Each frontend request includes SELECT option_value FROM wp_options WHERE option_name = 'widget_pages' LIMIT 1, but that option doesn't exist (same for widget_tag_cloud, widget_calendar, and widget_nav_menu).

Assuming everything so far is accurate, the attached patch would have get_settings() call WP_Widget::save_settings() with an empty array when no option is found in the database and the alt_option_name property isn't set. On the next request, the widget option would be autoloaded and not generate another query.

Attachments (1)

33292.patch (1.7 KB) - added by dlh 9 years ago.

Download all attachments as: .zip

Change History (3)

9 years ago

#1 @welcher
9 years ago

  • Keywords has-patch dev-feedback added

#2 @westonruter
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

@dlh: Your patch looks like a good alternate approach to what has been proposed on #26876. Please join in there.

Note: See TracTickets for help on using tickets.