From 56ae4bb6e9a08c5ada36b4c42ae4e22eaf288df7 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 4 Mar 2013 22:26:03 +0100 Subject: [PATCH 1/2] Cache: also check if the file id is already in the cache during upgrade Should solve upgrade issues if only some of the configured storages were migrated previously --- lib/files/cache/upgrade.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/files/cache/upgrade.php b/lib/files/cache/upgrade.php index 1fe4c58468..4d98abb2f8 100644 --- a/lib/files/cache/upgrade.php +++ b/lib/files/cache/upgrade.php @@ -64,7 +64,7 @@ class Upgrade { * @param array $data the data for the new cache */ function insert($data) { - if (!$this->inCache($data['storage'], $data['path_hash'])) { + if (!$this->inCache($data['storage'], $data['path_hash'], $data['id'])) { $insertQuery = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache` ( `fileid`, `storage`, `path`, `path_hash`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted` ) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'); @@ -78,12 +78,19 @@ class Upgrade { /** * @param string $storage * @param string $pathHash + * @param string $id * @return bool */ - function inCache($storage, $pathHash) { + function inCache($storage, $pathHash, $id) { $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?'); $result = $query->execute(array($storage, $pathHash)); - return (bool)$result->fetchRow(); + if ($result->fetchRow()) { + return true; + } else { + $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` = ?'); + $result = $query->execute(array($id)); + return (bool)$result->fetchRow(); + } } /** From 9d9acf24de482bdd5d0b700ba75631b246e5699b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 4 Mar 2013 23:19:55 +0100 Subject: [PATCH 2/2] Cache: more efficient detection for existing entries during upgrade --- lib/files/cache/upgrade.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/files/cache/upgrade.php b/lib/files/cache/upgrade.php index 4d98abb2f8..811d82d743 100644 --- a/lib/files/cache/upgrade.php +++ b/lib/files/cache/upgrade.php @@ -82,15 +82,9 @@ class Upgrade { * @return bool */ function inCache($storage, $pathHash, $id) { - $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?'); - $result = $query->execute(array($storage, $pathHash)); - if ($result->fetchRow()) { - return true; - } else { - $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` = ?'); - $result = $query->execute(array($id)); - return (bool)$result->fetchRow(); - } + $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(); } /**