Cache: more efficient upgrading

This commit is contained in:
Robin Appelman 2013-01-15 19:11:12 +01:00
parent 94068e5d08
commit 7debfac0dc
3 changed files with 26 additions and 10 deletions

View File

@ -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);

View File

@ -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;
}
/**

View File

@ -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']);
}
}
}