diff options
author | Bart Visscher <bartv@thisnet.nl> | 2013-02-25 21:35:11 +0100 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2013-07-21 23:17:36 +0200 |
commit | a48e9c488b7ccf22a911a0fb33b69ef782f63a81 (patch) | |
tree | cc7f3ebb26fc26efa62cbff253e4f50b80ef5ba8 /lib/db | |
parent | e3c5fea989f26a4ad16b841be25ea485c8aad8c4 (diff) | |
download | nextcloud-server-a48e9c488b7ccf22a911a0fb33b69ef782f63a81.tar.gz nextcloud-server-a48e9c488b7ccf22a911a0fb33b69ef782f63a81.zip |
Move prepared query cache handling to Connection wrapper
Diffstat (limited to 'lib/db')
-rw-r--r-- | lib/db/connection.php | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/lib/db/connection.php b/lib/db/connection.php index 7d56452678c..763251c1903 100644 --- a/lib/db/connection.php +++ b/lib/db/connection.php @@ -17,6 +17,9 @@ class Connection extends \Doctrine\DBAL\Connection { protected $adapter; + protected $preparedQueries = array(); + protected $cachingQueryStatementEnabled = true; + /** * Initializes a new instance of the Connection class. * @@ -47,9 +50,19 @@ class Connection extends \Doctrine\DBAL\Connection { */ public function prepare( $statement, $limit=null, $offset=null ) { $statement = $this->replaceTablePrefix($statement); - // TODO: limit & offset - // TODO: prepared statement cache - return parent::prepare($statement); + if (!is_null($limit) && $limit != -1) { + // TODO: limit & offset + } else { + if (isset($this->preparedQueries[$statement]) && $this->cachingQueryStatementEnabled) { + return $this->preparedQueries[$statement]; + } + } + $rawQuery = $statement; + $result = parent::prepare($statement); + if ((is_null($limit) || $limit == -1) && $this->cachingQueryStatementEnabled) { + $this->preparedQueries[$rawQuery] = $result; + } + return $result; } /** @@ -120,4 +133,13 @@ class Connection extends \Doctrine\DBAL\Connection { public function replaceTablePrefix($statement) { return str_replace( '*PREFIX*', $this->table_prefix, $statement ); } + + public function enableQueryStatementCaching() { + $this->cachingQueryStatementEnabled = true; + } + + public function disableQueryStatementCaching() { + $this->cachingQueryStatementEnabled = false; + $this->preparedQueries = array(); + } } |