diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-01-15 22:23:34 -0800 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-01-15 22:23:34 -0800 |
commit | 1f7bf57ecec772a0b9095ac758bff0a29a21152d (patch) | |
tree | 23d34ad0191f85e2b7ad3d28c24cc336179adf08 | |
parent | 0398bfffca723077eaa2ba0db7d60562c7826483 (diff) | |
parent | f18fc1c5101da7f46f5361c979194ee38acf3478 (diff) | |
download | nextcloud-server-1f7bf57ecec772a0b9095ac758bff0a29a21152d.tar.gz nextcloud-server-1f7bf57ecec772a0b9095ac758bff0a29a21152d.zip |
Merge pull request #1195 from owncloud/cache_prepared
Cache prepared statements in OC_DB
-rw-r--r-- | lib/db.php | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/db.php b/lib/db.php index 74e7ca5b0e0..5224d5ee7da 100644 --- a/lib/db.php +++ b/lib/db.php @@ -41,6 +41,8 @@ class OC_DB { const BACKEND_PDO=0; const BACKEND_MDB2=1; + static private $preparedQueries = array(); + /** * @var MDB2_Driver_Common */ @@ -121,6 +123,7 @@ class OC_DB { return true; } } + self::$preparedQueries = array(); // The global data we need $name = OC_Config::getValue( "dbname", "owncloud" ); $host = OC_Config::getValue( "dbhost", "" ); @@ -201,6 +204,7 @@ class OC_DB { return true; } } + self::$preparedQueries = array(); // The global data we need $name = OC_Config::getValue( "dbname", "owncloud" ); $host = OC_Config::getValue( "dbhost", "" ); @@ -321,7 +325,12 @@ class OC_DB { $query.=$limitsql; } } + } else { + if (isset(self::$preparedQueries[$query])) { + return self::$preparedQueries[$query]; + } } + $rawQuery = $query; // Optimize the query $query = self::processQuery( $query ); @@ -343,6 +352,9 @@ class OC_DB { } $result=new PDOStatementWrapper($result); } + if (is_null($limit) || $limit == -1) { + self::$preparedQueries[$rawQuery] = $result; + } return $result; } @@ -588,7 +600,7 @@ class OC_DB { error_log('DB error: '.$entry); OC_Template::printErrorPage( $entry ); } - + if($result->numRows() == 0) { $query = 'INSERT INTO "' . $table . '" ("' . implode('","', array_keys($input)) . '") VALUES("' @@ -623,7 +635,7 @@ class OC_DB { return $result->execute(); } - + /** * @brief does minor changes to query * @param string $query Query string |