Opened 17 months ago
Last modified 13 months ago
#58344 new enhancement
Connect to database on first query
Reported by: | spacedmonkey | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | |
Component: | Database | Keywords: | has-patch needs-testing-info |
Focuses: | performance | Cc: |
Description
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.
public function query( $query ) {
if ( ! $this->has_connected ) {
$this->db_connect();
}
if ( ! $this->ready ) {
$this->check_current_query = true;
return false;
}
Attachments (1)
Change History (10)
#2
@
17 months ago
- Version 0.71 deleted
I pointed this out 11 years ago in #19372 but never followed up :D
If it's simple enough to achieve and has a performance benefit then I'm in favour.
#3
@
17 months ago
One edge-case to consider is that currently WordPress will exit with a Site Unavailable
type error when the DB is unavailable, with this potential change if the query isn't made until the Footer or mid-post-render the page may partially render before hitting a wp_die()
condition (As you don't really want to return empty result-sets in the event of a DB-down scenario).
However, plugins like HyperDB and others do delay the DB connect until a query is made, so this might not be an actual issue that needs consideration.
That being said, If a persistent object cache is not in play, delaying until the first query will have very little change for most sites and scenario's.
This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.
13 months ago
#9
@
13 months ago
- Milestone changed from 6.4 to Future Release
This ticket was discussed during the Performance Bug Scrub meeting.
The patch requires both unit testing and manual testing. Therefore, we have decided to punt it to the next milestone. Please feel free to reassign it to the current milestone if it is ready for merging. Thank you.
Additional props to @joemcgill @spacedmonkey
Would love the thoughts of @johnjamesjacoby @johnbillion on this one.