jenkins-bot has submitted this change and it was merged.
Change subject: database: added DBConnRef wrapper to manage calling
reuseConnection()
......................................................................
database: added DBConnRef wrapper to manage calling reuseConnection()
Change-Id: Ifc9db62d1ac34d0c6a072d6f2d05bdcf73af14bb
---
M includes/AutoLoader.php
M includes/db/LoadBalancer.php
2 files changed, 47 insertions(+), 0 deletions(-)
Approvals:
Tim Starling: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php
index 6f8cd4b..2f0ac23 100644
--- a/includes/AutoLoader.php
+++ b/includes/AutoLoader.php
@@ -483,6 +483,7 @@
'DatabaseType' => 'includes/db/Database.php',
'DBAccessError' => 'includes/db/LBFactory.php',
'DBConnectionError' => 'includes/db/DatabaseError.php',
+ 'DBConnRef' => 'includes/db/LoadBalancer.php',
'DBError' => 'includes/db/DatabaseError.php',
'DBObject' => 'includes/db/DatabaseUtility.php',
'IORMRow' => 'includes/db/IORMRow.php',
diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php
index db709b5..ab200b4 100644
--- a/includes/db/LoadBalancer.php
+++ b/includes/db/LoadBalancer.php
@@ -546,6 +546,22 @@
}
/**
+ * Get a database connection handle reference
+ *
+ * The handle's methods wrap simply wrap those of a DatabaseBase handle
+ *
+ * @see LoadBalancer::getConnection() for parameter information
+ *
+ * @param integer $db
+ * @param mixed $groups
+ * @param string $wiki
+ * @return DBConnRef
+ */
+ public function getConnectionRef( $db, $groups = array(), $wiki = false
) {
+ return new DBConnRef( $this, $this->getConnection( $db,
$groups, $wiki ) );
+ }
+
+ /**
* Open a connection to the server given by the specified index
* Index must be an actual index into the array.
* If the server is already open, returns it.
@@ -1068,3 +1084,33 @@
$this->mLagTimes = null;
}
}
+
+/**
+ * Helper class to handle automatically marking connectons as reusable (via
RAII pattern)
+ *
+ * @ingroup Database
+ * @since 1.22
+ */
+class DBConnRef {
+ /** @var LoadBalancer */
+ protected $lb;
+ /** @var DatabaseBase */
+ protected $conn;
+
+ /**
+ * @param $lb LoadBalancer
+ * @param $conn DatabaseBase
+ */
+ public function __construct( LoadBalancer $lb, DatabaseBase $conn ) {
+ $this->lb = $lb;
+ $this->conn = $conn;
+ }
+
+ public function __call( $name, $arguments ) {
+ return call_user_func_array( array( $this->conn, $name ),
$arguments );
+ }
+
+ function __destruct() {
+ $this->lb->reuseConnection( $this->conn );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/72244
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifc9db62d1ac34d0c6a072d6f2d05bdcf73af14bb
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits