propagate folder size in the same query for write updates
This commit is contained in:
parent
fcec704174
commit
ddbbe1742f
|
@ -32,12 +32,13 @@ class SharedPropagator extends Propagator {
|
||||||
/**
|
/**
|
||||||
* @param string $internalPath
|
* @param string $internalPath
|
||||||
* @param int $time
|
* @param int $time
|
||||||
* @return array[] all propagated entries
|
* @param int $sizeDifference
|
||||||
|
* @return \array[] all propagated entries
|
||||||
*/
|
*/
|
||||||
public function propagateChange($internalPath, $time) {
|
public function propagateChange($internalPath, $time, $sizeDifference = 0) {
|
||||||
$source = $this->storage->getSourcePath($internalPath);
|
$source = $this->storage->getSourcePath($internalPath);
|
||||||
/** @var \OC\Files\Storage\Storage $storage */
|
/** @var \OC\Files\Storage\Storage $storage */
|
||||||
list($storage, $sourceInternalPath) = \OC\Files\Filesystem::resolvePath($source);
|
list($storage, $sourceInternalPath) = \OC\Files\Filesystem::resolvePath($source);
|
||||||
return $storage->getPropagator()->propagateChange($sourceInternalPath, $time);
|
return $storage->getPropagator()->propagateChange($sourceInternalPath, $time, $sizeDifference);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,9 +43,10 @@ class Propagator implements IPropagator {
|
||||||
/**
|
/**
|
||||||
* @param string $internalPath
|
* @param string $internalPath
|
||||||
* @param int $time
|
* @param int $time
|
||||||
* @return array[] all propagated cache entries
|
* @param int $sizeDifference number of bytes the file has grown
|
||||||
|
* @return array[] all propagated entries
|
||||||
*/
|
*/
|
||||||
public function propagateChange($internalPath, $time) {
|
public function propagateChange($internalPath, $time, $sizeDifference = 0) {
|
||||||
$cache = $this->storage->getCache($internalPath);
|
$cache = $this->storage->getCache($internalPath);
|
||||||
|
|
||||||
$parentId = $cache->getParentId($internalPath);
|
$parentId = $cache->getParentId($internalPath);
|
||||||
|
@ -58,7 +59,12 @@ class Propagator implements IPropagator {
|
||||||
}
|
}
|
||||||
$mtime = max($time, $entry['mtime']);
|
$mtime = max($time, $entry['mtime']);
|
||||||
|
|
||||||
$cache->update($parentId, ['mtime' => $mtime, 'etag' => $this->storage->getETag($entry['path'])]);
|
if ($entry['size'] === -1) {
|
||||||
|
$newSize = -1;
|
||||||
|
} else {
|
||||||
|
$newSize = $entry['size'] + $sizeDifference;
|
||||||
|
}
|
||||||
|
$cache->update($parentId, ['mtime' => $mtime, 'etag' => $this->storage->getETag($entry['path']), 'size' => $newSize]);
|
||||||
|
|
||||||
$parentId = $entry['parent'];
|
$parentId = $entry['parent'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,6 +198,7 @@ class Scanner extends BasicEmitter implements IScanner {
|
||||||
if (!empty($newData)) {
|
if (!empty($newData)) {
|
||||||
$data['fileid'] = $this->addToCache($file, $newData, $fileId);
|
$data['fileid'] = $this->addToCache($file, $newData, $fileId);
|
||||||
}
|
}
|
||||||
|
$data['oldSize'] = $cacheData['size'];
|
||||||
|
|
||||||
// post-emit only if it was a file. By that we avoid counting/treating folders as files
|
// post-emit only if it was a file. By that we avoid counting/treating folders as files
|
||||||
if ($data['mimetype'] !== 'httpd/unix-directory') {
|
if ($data['mimetype'] !== 'httpd/unix-directory') {
|
||||||
|
|
|
@ -118,9 +118,15 @@ class Updater implements IUpdater {
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->scanner->scan($path, Scanner::SCAN_SHALLOW, -1, false);
|
$data = $this->scanner->scan($path, Scanner::SCAN_SHALLOW, -1, false);
|
||||||
$this->correctParentStorageMtime($path);
|
if (isset($data['oldSize']) && isset($data['size'])) {
|
||||||
|
$sizeDifference = $data['size'] - $data['oldSize'];
|
||||||
|
} else {
|
||||||
|
// scanner didn't provide size info, fallback to full size calculation
|
||||||
|
$sizeDifference = 0;
|
||||||
$this->cache->correctFolderSize($path, $data);
|
$this->cache->correctFolderSize($path, $data);
|
||||||
$this->propagator->propagateChange($path, $time);
|
}
|
||||||
|
$this->correctParentStorageMtime($path);
|
||||||
|
$this->propagator->propagateChange($path, $time, $sizeDifference);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -87,7 +87,9 @@ class FileCache extends \Test_Cache {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown() {
|
protected function tearDown() {
|
||||||
|
if ($this->instance) {
|
||||||
$this->instance->remove('hack', 'hack');
|
$this->instance->remove('hack', 'hack');
|
||||||
|
}
|
||||||
|
|
||||||
\OC_User::setUserId($this->user);
|
\OC_User::setUserId($this->user);
|
||||||
\OC::$server->getConfig()->setSystemValue('cachedirectory', $this->datadir);
|
\OC::$server->getConfig()->setSystemValue('cachedirectory', $this->datadir);
|
||||||
|
|
Loading…
Reference in New Issue