[Pkg-owncloud-commits] [php-sabredav] 200/220: Saving some time by caching database connections.
David Prévot
taffit at moszumanska.debian.org
Thu May 12 01:21:28 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabredav.
commit 16482ecef63638018dab1c2f982b98c5683cd99f
Author: Evert Pot <me at evertpot.com>
Date: Thu Apr 28 16:32:24 2016 +0700
Saving some time by caching database connections.
---
tests/Sabre/DAV/DbTestHelperTrait.php | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/tests/Sabre/DAV/DbTestHelperTrait.php b/tests/Sabre/DAV/DbTestHelperTrait.php
index 4a3a4e2..98b86c6 100644
--- a/tests/Sabre/DAV/DbTestHelperTrait.php
+++ b/tests/Sabre/DAV/DbTestHelperTrait.php
@@ -5,6 +5,12 @@ namespace Sabre\DAV;
use PDOException;
use PDO;
+class DbCache {
+
+ static $cache = [];
+
+}
+
trait DbTestHelperTrait {
/**
@@ -12,9 +18,6 @@ trait DbTestHelperTrait {
*/
public $driver = null;
- private $db = [];
-
-
/**
* Returns a fully configured PDO object.
*
@@ -24,10 +27,11 @@ trait DbTestHelperTrait {
if (!$this->driver) {
throw new \Exception('You must set the $driver public property');
- }
+ }
- if (isset($this->db[$this->driver])) {
- return $this->db[$this->driver];
+ if (isset(DbCache::$cache[$this->driver])) {
+ return DbCache::$cache[$this->driver];
+ } else {
}
try {
@@ -38,7 +42,7 @@ trait DbTestHelperTrait {
$pdo = new PDO(SABRE_MYSQLDSN, SABRE_MYSQLUSER, SABRE_MYSQLPASS);
break;
case 'sqlite' :
- $pdo = new \PDO('sqlite:' . SABRE_TEMPDIR . '/pdobackend');
+ $pdo = new \PDO('sqlite:' . SABRE_TEMPDIR . '/testdb');
break;
case 'pgsql' :
$pdo = new \PDO(SABRE_PGSQLDSN);
@@ -55,7 +59,7 @@ trait DbTestHelperTrait {
}
- $this->db[$this->driver] = $pdo;
+ DbCache::$cache[$this->driver] = $pdo;
return $pdo;
}
@@ -111,4 +115,16 @@ trait DbTestHelperTrait {
}
+ function tearDown() {
+
+ switch($this->driver) {
+
+ case 'sqlite' :
+ // Recreating sqlite, just in case
+ unset(DbCache::$cache[$this->driver]);
+ unlink(SABRE_TEMPDIR . '/testdb');
+ }
+
+ }
+
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-php/php-sabredav.git
More information about the Pkg-owncloud-commits
mailing list