Skip to content
Snippets Groups Projects
Commit ba323efc authored by ale's avatar ale
Browse files

Merge branch 'cleanup-db-patches' into 'master'

Clean up the HyperDB patches

See merge request !1
parents 526de9bd 837c75c3
Branches
No related tags found
1 merge request!1Clean up the HyperDB patches
...@@ -18,11 +18,9 @@ ...@@ -18,11 +18,9 @@
}, },
"wpackagist-plugin/hyperdb": { "wpackagist-plugin/hyperdb": {
"A few fixes to the global wpdb_hash instance (moved into wpdb)": "patches/hyperdb/0106-a-few-fixes-to-the-global-wpdb_hash-instance-moved-i.patch", "A few fixes to the global wpdb_hash instance (moved into wpdb)": "patches/hyperdb/0106-a-few-fixes-to-the-global-wpdb_hash-instance-moved-i.patch",
"Profiling: changing the define AI_DB_PROFILER to true will enable query logging (use with caution!)": "patches/hyperdb/0116-Performance-tweaks.patch",
"Prevent mysql-proxy to cache the admin section": "patches/hyperdb/0117-prevent-mysql-proxy-to-cache-the-admin-section.patch",
"Awful workaround (?)": "patches/hyperdb/0126-awful-workaround.patch", "Awful workaround (?)": "patches/hyperdb/0126-awful-workaround.patch",
"Added optional logging": "patches/hyperdb/0158-Added-optional-logging.patch", "Added optional logging": "patches/hyperdb/0158-Added-optional-logging.patch",
"Adding extreme debugging when wp_debug is true": "patches/hyperdb/0161-adding-extreme-debugging-when-wp_debug-is-true.patch" "Add support for SHOW TABLES LIKE queries": "patches/hyperdb/show-tables-like.patch"
}, },
"wpackagist-plugin/more-privacy-options": { "wpackagist-plugin/more-privacy-options": {
"Do send mail on privacy setting change": "patches/plugins/more-privacy-options.patch" "Do send mail on privacy setting change": "patches/plugins/more-privacy-options.patch"
......
From b07f1d25505e064dc076ff68ec81bf19c459a3db Mon Sep 17 00:00:00 2001
From: Joe Oblivian <0blivian@insiberia.net>
Date: Thu, 15 Sep 2011 20:43:47 +0200
Subject: [PATCH 116/229] Performance tweaks:
- Cache more aggressively
- Use persistent connections
Profiling: changing the define AI_DB_PROFILER to true will enable query logging (use with caution!)
---
diff --git a/wp-content/db.php b/wp-content/db.php
index 18d53a1b..99ff86ed 100644
--- a/wp-content/db.php
+++ b/wp-content/db.php
@@ -1,4 +1,6 @@
<?php
+//AI patch: set to true if you want to activate query profiling
+define('AI_DB_PROFILER', false);
/*
Plugin Name: HyperDB
@@ -1441,6 +1443,23 @@ class hyperdb extends wpdb {
} // class hyperdb
-$wpdb = new hyperdb();
+/**
+ * AI custom: Logs all queries for debugging purposes
+ */
+function ai_log_db_queries($query, $time, $backtrace=null, hyperdb $obj ) {
+ $fh = fopen( ABSPATH . '/profiling/noblogs_queries_'. date('Ymd') . '.log', 'a');
+ if (!$fh) {
+ return array($query, $time, $backtrace);
+ }
+ fwrite($fh, sprintf("##\n#Date: %s\n#Query time: %s\n%s\n", date('r'), $time, $query));
+ fclose($fh);
+ return array($query, $time, $backtrace);
+}
+
+$wpdb = new hyperdb();
+if ( AI_DB_PROFILER === true ) {
+ $wpdb->save_queries = true;
+ $wpdb->save_query_callback = 'ai_log_db_queries';
+}
require( DB_CONFIG_FILE );
--
2.17.1
From aeb256f01ca5cf7d9f8aa8e46b821f4a9896aa14 Mon Sep 17 00:00:00 2001
From: Joe Oblivian <0blivian@insiberia.net>
Date: Sun, 18 Sep 2011 19:52:42 +0200
Subject: [PATCH 117/229] prevent mysql-proxy to cache the admin section
---
wp-content/db.php | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/wp-content/db.php b/wp-content/db.php
index 99ff86ed..79c189e5 100644
--- a/wp-content/db.php
+++ b/wp-content/db.php
@@ -872,6 +872,11 @@ class hyperdb extends wpdb {
$statement_after_query = $this->run_callbacks( 'statement_after_query' );
$query_for_log = $query;
+ // A/I: prevent mysql-proxy to cache the admin section
+ if (strpos($_SERVER['REQUEST_URI'], '/wp-admin/') !== false) {
+ $query .= ' /* NO CACHE */';
+ }
+
$this->timer_start();
if ( $statement_before_query ) {
$query_for_log = "$statement_before_query; $query_for_log";
--
2.17.1
...@@ -11,15 +11,6 @@ diff --git a/wp-content/db.php b/wp-content/db.php ...@@ -11,15 +11,6 @@ diff --git a/wp-content/db.php b/wp-content/db.php
index abc3353e..0f9f5a1e 100644 index abc3353e..0f9f5a1e 100644
--- a/wp-content/db.php --- a/wp-content/db.php
+++ b/wp-content/db.php +++ b/wp-content/db.php
@@ -55,7 +55,7 @@ define( 'HYPERDB_SERVER_GONE_ERROR', 2006 ); // MySQL server has gone away
class hyperdb extends wpdb {
/**
- * A/I patch!
+ * A/I patch!
* store a FlexiHash() instance here.
*/
var $hash_map;
@@ -680,16 +680,19 @@ class hyperdb extends wpdb { @@ -680,16 +680,19 @@ class hyperdb extends wpdb {
$success = false; $success = false;
$this->last_connection = compact('dbhname', 'host', 'port', 'user', 'name', 'tcp', 'elapsed', 'success'); $this->last_connection = compact('dbhname', 'host', 'port', 'user', 'name', 'tcp', 'elapsed', 'success');
...@@ -50,26 +41,6 @@ index abc3353e..0f9f5a1e 100644 ...@@ -50,26 +41,6 @@ index abc3353e..0f9f5a1e 100644
} }
if ( ! $success || ! isset( $this->dbhs[$dbhname] ) || ! $this->is_mysql_connection( $this->dbhs[$dbhname] ) ) { if ( ! $success || ! isset( $this->dbhs[$dbhname] ) || ! $this->is_mysql_connection( $this->dbhs[$dbhname] ) ) {
@@ -723,8 +726,8 @@ class hyperdb extends wpdb {
$collate = null;
$this->set_charset($this->dbhs[$dbhname], $charset, $collate);
-
- if ( !isset( $charset ) )
+
+ if ( !isset( $charset ) )
$charset = null;
if ( !isset( $collate ) )
@@ -885,7 +888,7 @@ class hyperdb extends wpdb {
if (strpos($_SERVER['REQUEST_URI'], '/wp-admin/') !== false) {
$query .= ' /* NO CACHE */';
}
-
+
$this->timer_start();
if ( $statement_before_query ) {
$query_for_log = "$statement_before_query; $query_for_log";
-- --
2.17.1 2.17.1
From 0d0a76d87eba5cf15114c21478d73e1d4a80c93f Mon Sep 17 00:00:00 2001
From: Joe <joe@autistici.org>
Date: Fri, 3 May 2013 16:42:59 +0200
Subject: [PATCH 161/229] adding extreme debugging when wp_debug is true
---
wp-content/db.php | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/wp-content/db.php b/wp-content/db.php
index 0f9f5a1e..2bd49b41 100644
--- a/wp-content/db.php
+++ b/wp-content/db.php
@@ -416,6 +416,11 @@ class hyperdb extends wpdb {
$this->run_callbacks( 'dataset_found', $dataset );
+ if (WP_DEBUG === true) {
+ $_ai_msg = sprintf("We choose dataset %s for query '%s'", $this->dataset, $query);
+ $this->print_error($_ai_msg);
+ }
+
if ( empty( $this->hyper_servers ) ) {
if ( $this->is_mysql_connection( $this->dbh ) )
return $this->dbh;
--
2.17.1
diff --git a/wp-content/db.php b/wp-content/db.php
index f900d305..f819e225 100644
--- a/wp-content/db.php
+++ b/wp-content/db.php
@@ -306,6 +312,12 @@ class hyperdb extends wpdb {
. ')\W([\w-]+)\W/is', $q, $maybe) )
return $maybe[1];
+ // SHOW TABLES LIKE (used in some plugins)
+ if ( preg_match('/^\s*'
+ . 'SHOW\s+TABLES\s+LIKE\s+'
+ . '\W(\w+)\W/is', $q, $maybe) )
+ return $maybe[1];
+
// Big pattern for the rest of the table-related queries in MySQL 5.0
if ( preg_match('/^\s*(?:'
. '(?:EXPLAIN\s+(?:EXTENDED\s+)?)?SELECT.*?\s+FROM'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment