Cache: more efficient upgrading
This commit is contained in:
parent
94068e5d08
commit
7debfac0dc
|
@ -10,10 +10,12 @@ $legacy = new \OC\Files\Cache\Legacy($user);
|
||||||
if ($legacy->hasItems()) {
|
if ($legacy->hasItems()) {
|
||||||
OC_Hook::connect('\OC\Files\Cache\Upgrade', 'migrate_path', $listener, 'upgradePath');
|
OC_Hook::connect('\OC\Files\Cache\Upgrade', 'migrate_path', $listener, 'upgradePath');
|
||||||
|
|
||||||
|
OC_DB::beginTransaction();
|
||||||
$upgrade = new \OC\Files\Cache\Upgrade($legacy);
|
$upgrade = new \OC\Files\Cache\Upgrade($legacy);
|
||||||
$count = $legacy->getCount();
|
$count = $legacy->getCount();
|
||||||
$eventSource->send('total', $count);
|
$eventSource->send('total', $count);
|
||||||
$upgrade->upgradePath('/' . $user . '/files');
|
$upgrade->upgradePath('/' . $user . '/files');
|
||||||
|
OC_DB::commit();
|
||||||
}
|
}
|
||||||
\OC\Files\Cache\Upgrade::upgradeDone($user);
|
\OC\Files\Cache\Upgrade::upgradeDone($user);
|
||||||
$eventSource->send('done', true);
|
$eventSource->send('done', true);
|
||||||
|
|
|
@ -14,6 +14,8 @@ namespace OC\Files\Cache;
|
||||||
class Legacy {
|
class Legacy {
|
||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
|
private $cacheHasItems = null;
|
||||||
|
|
||||||
public function __construct($user) {
|
public function __construct($user) {
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
@ -34,17 +36,23 @@ class Legacy {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function hasItems() {
|
function hasItems() {
|
||||||
|
if (!is_null($this->cacheHasItems)) {
|
||||||
|
return $this->cacheHasItems;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
$query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*fscache` WHERE `user` = ? LIMIT 1');
|
$query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*fscache` WHERE `user` = ? LIMIT 1');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
$this->cacheHasItems = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$result = $query->execute(array($this->user));
|
$result = $query->execute(array($this->user));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
$this->cacheHasItems = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (bool)$result->fetchRow();
|
$this->cacheHasItems = (bool)$result->fetchRow();
|
||||||
|
return $this->cacheHasItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,15 +43,21 @@ class Upgrade {
|
||||||
$data = $this->getNewData($row);
|
$data = $this->getNewData($row);
|
||||||
$this->insert($data);
|
$this->insert($data);
|
||||||
|
|
||||||
$children = $this->legacy->getChildren($data['id']);
|
$this->upgradeChilds($data['id'], $mode);
|
||||||
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);
|
* @param int $id
|
||||||
} else {
|
*/
|
||||||
$this->upgradePath($child['path']);
|
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']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue