aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2013-01-15 19:11:12 +0100
committerRobin Appelman <icewind@owncloud.com>2013-01-15 19:11:12 +0100
commit7debfac0dc8f602168d8db480cfd4757b4d612b0 (patch)
tree98398af95bc5c6b93793e6bc80ad8dba5deea237
parent94068e5d08cba776e410d925e26037d442b5bc62 (diff)
downloadnextcloud-server-7debfac0dc8f602168d8db480cfd4757b4d612b0.tar.gz
nextcloud-server-7debfac0dc8f602168d8db480cfd4757b4d612b0.zip
Cache: more efficient upgrading
-rw-r--r--apps/files/ajax/upgrade.php2
-rw-r--r--lib/files/cache/legacy.php10
-rw-r--r--lib/files/cache/upgrade.php24
3 files changed, 26 insertions, 10 deletions
diff --git a/apps/files/ajax/upgrade.php b/apps/files/ajax/upgrade.php
index 965c0073b8a..7237b02c0b0 100644
--- a/apps/files/ajax/upgrade.php
+++ b/apps/files/ajax/upgrade.php
@@ -10,10 +10,12 @@ $legacy = new \OC\Files\Cache\Legacy($user);
if ($legacy->hasItems()) {
OC_Hook::connect('\OC\Files\Cache\Upgrade', 'migrate_path', $listener, 'upgradePath');
+ OC_DB::beginTransaction();
$upgrade = new \OC\Files\Cache\Upgrade($legacy);
$count = $legacy->getCount();
$eventSource->send('total', $count);
$upgrade->upgradePath('/' . $user . '/files');
+ OC_DB::commit();
}
\OC\Files\Cache\Upgrade::upgradeDone($user);
$eventSource->send('done', true);
diff --git a/lib/files/cache/legacy.php b/lib/files/cache/legacy.php
index ee10a1c1350..33d4b8e7c9f 100644
--- a/lib/files/cache/legacy.php
+++ b/lib/files/cache/legacy.php
@@ -14,6 +14,8 @@ namespace OC\Files\Cache;
class Legacy {
private $user;
+ private $cacheHasItems = null;
+
public function __construct($user) {
$this->user = $user;
}
@@ -34,17 +36,23 @@ class Legacy {
* @return bool
*/
function hasItems() {
+ if (!is_null($this->cacheHasItems)) {
+ return $this->cacheHasItems;
+ }
try {
$query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*fscache` WHERE `user` = ? LIMIT 1');
} catch (\Exception $e) {
+ $this->cacheHasItems = false;
return false;
}
try {
$result = $query->execute(array($this->user));
} catch (\Exception $e) {
+ $this->cacheHasItems = false;
return false;
}
- return (bool)$result->fetchRow();
+ $this->cacheHasItems = (bool)$result->fetchRow();
+ return $this->cacheHasItems;
}
/**
diff --git a/lib/files/cache/upgrade.php b/lib/files/cache/upgrade.php
index 1032e0a844c..cd9a9e91a8c 100644
--- a/lib/files/cache/upgrade.php
+++ b/lib/files/cache/upgrade.php
@@ -43,15 +43,21 @@ class Upgrade {
$data = $this->getNewData($row);
$this->insert($data);
- $children = $this->legacy->getChildren($data['id']);
- foreach ($children as $child) {
- if ($mode == Scanner::SCAN_SHALLOW) {
- $childData = $this->getNewData($child);
- \OC_Hook::emit('\OC\Files\Cache\Upgrade', 'migrate_path', $child['path']);
- $this->insert($childData);
- } else {
- $this->upgradePath($child['path']);
- }
+ $this->upgradeChilds($data['id'], $mode);
+ }
+ }
+
+ /**
+ * @param int $id
+ */
+ function upgradeChilds($id, $mode = Scanner::SCAN_RECURSIVE) {
+ $children = $this->legacy->getChildren($id);
+ foreach ($children as $child) {
+ $childData = $this->getNewData($child);
+ \OC_Hook::emit('\OC\Files\Cache\Upgrade', 'migrate_path', $child['path']);
+ $this->insert($childData);
+ if ($mode == Scanner::SCAN_RECURSIVE) {
+ $this->upgradeChilds($child['id']);
}
}
}