From 92d18cf32edab81ac77f547cfa718cf28a573c92 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Fri, 04 Oct 2013 07:50:12 -0400
Subject: [PATCH] New option to disable the use of already established dsnw connections for subsequent reads
---
program/lib/Roundcube/rcube_db.php | 15 ++++++++++++---
config/defaults.inc.php | 3 +++
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/config/defaults.inc.php b/config/defaults.inc.php
index 874621d..66db040 100644
--- a/config/defaults.inc.php
+++ b/config/defaults.inc.php
@@ -30,6 +30,9 @@
// useful for database replication
$config['db_dsnr'] = '';
+// Disable the use of already established dsnw connections for subsequent reads
+$config['db_dsnw_noread'] = false;
+
// use persistent db-connections
// beware this will not "always" work as expected
// see: http://www.php.net/manual/en/features.persistent-connections.php
diff --git a/program/lib/Roundcube/rcube_db.php b/program/lib/Roundcube/rcube_db.php
index e66226f..2861a91 100644
--- a/program/lib/Roundcube/rcube_db.php
+++ b/program/lib/Roundcube/rcube_db.php
@@ -32,6 +32,7 @@
protected $db_connected = false; // Already connected ?
protected $db_mode; // Connection mode
protected $dbh; // Connection handle
+ protected $dbhs = array();
protected $db_error = false;
protected $db_error_msg = '';
@@ -97,6 +98,7 @@
$this->db_dsnw = $db_dsnw;
$this->db_dsnr = $db_dsnr;
$this->db_pconn = $pconn;
+ $this->db_dsnw_noread = rcube::get_instance()->config->get('db_dsnw_noread', false);
$this->db_dsnw_array = self::parse_dsn($db_dsnw);
$this->db_dsnr_array = self::parse_dsn($db_dsnr);
@@ -112,6 +114,13 @@
{
$this->db_error = false;
$this->db_error_msg = null;
+
+ // return existing handle
+ if ($this->dbhs[$mode]) {
+ $this->dbh = $this->dbhs[$mode];
+ $this->db_mode = $mode;
+ return $this->dbh;
+ }
// Get database specific connection options
$dsn_string = $this->dsn_string($dsn);
@@ -147,6 +156,7 @@
}
$this->dbh = $dbh;
+ $this->dbhs[$mode] = $dbh;
$this->db_mode = $mode;
$this->db_connected = true;
$this->conn_configure($dsn, $dbh);
@@ -190,14 +200,13 @@
// Already connected
if ($this->db_connected) {
- // connected to db with the same or "higher" mode
- if ($this->db_mode == 'w' || $this->db_mode == $mode) {
+ // connected to db with the same or "higher" mode (if allowed)
+ if ($this->db_mode == $mode || $this->db_mode == 'w' && !$this->db_dsnw_noread) {
return;
}
}
$dsn = ($mode == 'r') ? $this->db_dsnr_array : $this->db_dsnw_array;
-
$this->dsn_connect($dsn, $mode);
// use write-master when read-only fails
--
Gitblit v1.9.1