[wp-trac] [WordPress Trac] #58344: Connect to database on first query

WordPress Trac noreply at wordpress.org
Wed May 17 13:55:48 UTC 2023


#58344: Connect to database on first query
--------------------------+-----------------------------
 Reporter:  spacedmonkey  |      Owner:  (none)
     Type:  enhancement   |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Database      |    Version:  0.71
 Severity:  normal        |   Keywords:
  Focuses:  performance   |
--------------------------+-----------------------------
 Currently there is the database connection is made in `__construct` method
 by calling `db_connect` method. However with sites with persistent object
 caching enabled, this connection to the database may not be needed. It is
 common now for requests to have no database queries at all if persistent
 object caching is setup.

 Moving the `db_connect` call to the `query` method like this.

 {{{#!php
         public function query( $query ) {
                 if ( ! $this->has_connected ) {
                        $this->db_connect();
                 }
                 if ( ! $this->ready ) {
                         $this->check_current_query = true;
                         return false;
                 }

 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58344>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list