Split of cache writes in the scanner to their own methods
This commit is contained in:
parent
a31f089266
commit
0158788a2a
|
@ -124,10 +124,8 @@ class Scanner extends BasicEmitter {
|
|||
// prevent empty etag
|
||||
if (empty($cacheData['etag'])) {
|
||||
$etag = $data['etag'];
|
||||
$propagateETagChange = true;
|
||||
} else {
|
||||
$etag = $cacheData['etag'];
|
||||
$propagateETagChange = false;
|
||||
}
|
||||
// only reuse data if the file hasn't explicitly changed
|
||||
if (isset($data['storage_mtime']) && isset($cacheData['storage_mtime']) && $data['storage_mtime'] === $cacheData['storage_mtime']) {
|
||||
|
@ -136,22 +134,6 @@ class Scanner extends BasicEmitter {
|
|||
}
|
||||
if ($reuseExisting & self::REUSE_ETAG) {
|
||||
$data['etag'] = $etag;
|
||||
if ($propagateETagChange) {
|
||||
$parent = $file;
|
||||
while ($parent !== '') {
|
||||
$parent = dirname($parent);
|
||||
if ($parent === '.') {
|
||||
$parent = '';
|
||||
}
|
||||
$parentCacheData = $this->cache->get($parent);
|
||||
\OC_Hook::emit('Scanner', 'updateCache', array('file' => $file, 'data' => $data));
|
||||
if($this->cacheActive) {
|
||||
$this->cache->update($parentCacheData['fileid'], array(
|
||||
'etag' => $this->storage->getETag($parent),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Only update metadata that has changed
|
||||
|
@ -166,24 +148,52 @@ class Scanner extends BasicEmitter {
|
|||
}
|
||||
}
|
||||
if (!empty($newData)) {
|
||||
\OC_Hook::emit('Scanner', 'addToCache', array('file' => $file, 'data' => $newData));
|
||||
if($this->cacheActive) {
|
||||
$data['fileid'] = $this->cache->put($file, $newData);
|
||||
}
|
||||
$data['fileid'] = $this->addToCache($file, $newData);
|
||||
$this->emit('\OC\Files\Cache\Scanner', 'postScanFile', array($file, $this->storageId));
|
||||
\OC_Hook::emit('\OC\Files\Cache\Scanner', 'post_scan_file', array('path' => $file, 'storage' => $this->storageId));
|
||||
}
|
||||
} else {
|
||||
\OC_Hook::emit('Scanner', 'removeFromCache', array('file' => $file));
|
||||
if($this->cacheActive) {
|
||||
$this->cache->remove($file);
|
||||
}
|
||||
$this->removeFromCache($file);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function removeFromCache($path) {
|
||||
\OC_Hook::emit('Scanner', 'removeFromCache', array('file' => $path));
|
||||
$this->emit('\OC\Files\Cache\Scanner', 'removeFromCache', array($path));
|
||||
if ($this->cacheActive) {
|
||||
$this->cache->remove($path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param array $data
|
||||
* @return int the id of the added file
|
||||
*/
|
||||
protected function addToCache($path, $data) {
|
||||
\OC_Hook::emit('Scanner', 'addToCache', array('file' => $path, 'data' => $data));
|
||||
$this->emit('\OC\Files\Cache\Scanner', 'addToCache', array($path, $this->storageId, $data));
|
||||
if ($this->cacheActive) {
|
||||
return $this->cache->put($path, $data);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param array $data
|
||||
*/
|
||||
protected function updateCache($path, $data) {
|
||||
\OC_Hook::emit('Scanner', 'addToCache', array('file' => $path, 'data' => $data));
|
||||
if ($this->cacheActive) {
|
||||
$this->cache->put($path, $data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* scan a folder and all it's children
|
||||
*
|
||||
|
@ -246,8 +256,7 @@ class Scanner extends BasicEmitter {
|
|||
$size += $data['size'];
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $ex){
|
||||
} catch (\Doctrine\DBAL\DBALException $ex) {
|
||||
// might happen if inserting duplicate while a scanning
|
||||
// process is running in parallel
|
||||
// log and ignore
|
||||
|
@ -260,10 +269,7 @@ class Scanner extends BasicEmitter {
|
|||
$removedChildren = \array_diff($existingChildren, $newChildren);
|
||||
foreach ($removedChildren as $childName) {
|
||||
$child = ($path) ? $path . '/' . $childName : $childName;
|
||||
\OC_Hook::emit('Scanner', 'removeFromCache', array('file' => $child));
|
||||
if($this->cacheActive) {
|
||||
$this->cache->remove($child);
|
||||
}
|
||||
$this->removeFromCache($child);
|
||||
}
|
||||
\OC_DB::commit();
|
||||
if ($exceptionOccurred) {
|
||||
|
@ -282,11 +288,7 @@ class Scanner extends BasicEmitter {
|
|||
$size += $childSize;
|
||||
}
|
||||
}
|
||||
$newData = array('size' => $size);
|
||||
\OC_Hook::emit('Scanner', 'addToCache', array('file' => $child, 'data' => $newData));
|
||||
if($this->cacheActive) {
|
||||
$this->cache->put($path, $newData);
|
||||
}
|
||||
$this->updateCache($path, array('size' => $size));
|
||||
}
|
||||
$this->emit('\OC\Files\Cache\Scanner', 'postScanFolder', array($path, $this->storageId));
|
||||
return $size;
|
||||
|
@ -296,6 +298,7 @@ class Scanner extends BasicEmitter {
|
|||
* check if the file should be ignored when scanning
|
||||
* NOTE: files with a '.part' extension are ignored as well!
|
||||
* prevents unfinished put requests to be scanned
|
||||
*
|
||||
* @param string $file
|
||||
* @return boolean
|
||||
*/
|
||||
|
@ -323,6 +326,7 @@ class Scanner extends BasicEmitter {
|
|||
|
||||
/**
|
||||
* Set whether the cache is affected by scan operations
|
||||
*
|
||||
* @param boolean $active The active state of the cache
|
||||
*/
|
||||
public function setCacheActive($active) {
|
||||
|
|
Loading…
Reference in New Issue