summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2013-03-22 13:36:31 +0100
committerArthur Schiwon <blizzz@owncloud.com>2013-03-22 13:36:31 +0100
commit0d075df15ed5449e86e110f56d0d7f62cc342b95 (patch)
tree47dd361cf5d17ebf0a5f34212f2a68473c5f11b4
parentc82f43ee55551807a0fad2dce0d75d70f4b0966c (diff)
downloadnextcloud-server-0d075df15ed5449e86e110f56d0d7f62cc342b95.tar.gz
nextcloud-server-0d075df15ed5449e86e110f56d0d7f62cc342b95.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 ffdf450c9d8..549d7076ce8 100644
--- a/lib/files/cache/upgrade.php
+++ b/lib/files/cache/upgrade.php
@@ -67,11 +67,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']));
@@ -85,7 +87,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();
}