aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2013-03-22 13:36:31 +0100
committerArthur Schiwon <blizzz@owncloud.com>2013-03-27 19:12:04 +0100
commit9d25058905f8a50e729397052d39eb84dcb9fe01 (patch)
tree45a0b63f7d99ce23bc6543943e8f5a31ae3b2e16
parent7839ec5093272fb516ad701b79387af158c8994d (diff)
downloadnextcloud-server-9d25058905f8a50e729397052d39eb84dcb9fe01.tar.gz
nextcloud-server-9d25058905f8a50e729397052d39eb84dcb9fe01.zip
Performance: prepare queries only once
-rw-r--r--lib/files/cache/upgrade.php15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/files/cache/upgrade.php b/lib/files/cache/upgrade.php
index cf2eb7f9ef8..efb06a2b943 100644
--- a/lib/files/cache/upgrade.php
+++ b/lib/files/cache/upgrade.php
@@ -72,11 +72,13 @@ class Upgrade {
* @param array $data the data for the new cache
*/
function insert($data) {
- if (!$this->inCache($data['storage'], $data['path_hash'], $data['id'])) {
+ static $insertQuery = null;
+ if(is_null($insertQuery)) {
$insertQuery = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache`
- ( `fileid`, `storage`, `path`, `path_hash`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `etag` )
- VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
-
+ ( `fileid`, `storage`, `path`, `path_hash`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `etag` )
+ VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
+ }
+ if (!$this->inCache($data['storage'], $data['path_hash'], $data['id'])) {
$insertQuery->execute(array($data['id'], $data['storage'],
$data['path'], $data['path_hash'], $data['parent'], $data['name'],
$data['mimetype'], $data['mimepart'], $data['size'], $data['mtime'], $data['encrypted'], $data['etag']));
@@ -92,7 +94,10 @@ class Upgrade {
* @return bool
*/
function inCache($storage, $pathHash, $id) {
- $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE (`storage` = ? AND `path_hash` = ?) OR `fileid` = ?');
+ static $query = null;
+ if(is_null($query)) {
+ $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE (`storage` = ? AND `path_hash` = ?) OR `fileid` = ?');
+ }
$result = $query->execute(array($storage, $pathHash, $id));
return (bool)$result->fetchRow();
}