Support » Requests and Feedback » Possible improvement of get_option()

  • While playing around with certain themes and plugins I noticed that a lot of them cause unnecessary SELECTs to the database because they try to access non-existing options using get_option().

    So I thought about a way on how to improve that function.

    Currently the get_option()-function only “knows” about those options with “autoload = yes”. It loads them once per request and caches them. Why not cache the names of all “autoload = no” options, too?

    That way, the get_option()-function could easily decide if it should query the db or not. If a plugin for example contains get_option(‘foobar’) and foobar is neither in the cache for “autoload = yes” options and in the list of “autoload = no” options there is no reason to query the DB. If it only exists in the “autoload = no” cache it should be queried on-the-fly (and the value stored in the cache after that).

    Only bit of extra-logic i would add is that options with names beginning with “_” should be treated the same way as options are treated now (this would prevent the new function from loading all those _transient_* options).

    In my experience, this would lead to much fewer unnecessary queries and would only cost a little bit more memory (at least I haven’t seen a blog with more than 10-20 autoload = no options).

  • The topic ‘Possible improvement of get_option()’ is closed to new replies.