[wp-trac] [WordPress Trac] #26876: Default widgets causing unnecessary database queries

WordPress Trac noreply at wordpress.org
Mon Jan 20 16:17:00 UTC 2014


#26876: Default widgets causing unnecessary database queries
--------------------------+------------------------------
 Reporter:  codydh        |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Widgets       |     Version:  3.0
 Severity:  minor         |  Resolution:
 Keywords:  has-patch     |
--------------------------+------------------------------
Changes (by kovshenin):

 * keywords:  needs-patch => has-patch


Comment:

 Nice catch! This is not only related to core widgets. Any registered
 widget without a database entry will fire a query during `widgets_init`.
 We could solve it for core widgets by adding some fields to
 `populate_options()`, however I think we can do better than that :)

 During `_register()` we really only need that setting to determine how
 many times `_register_one()` should be called, so for widgets that haven't
 been used (not in a sidebar and not in the inactive widgets array, and no
 db entry) that's always one.

 [attachment:26876.diff] attempts to fix this with `is_active_widget()`.

 This does mean that an additional regex will run during `widgets_init` for
 every available widget, but I don't think that will ever be a concern
 since we use `_get_widget_id_base` and the regex is most likely cached by
 then.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/26876#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list