Merge pull request #1054 from nextcloud/less-cache-hits
Reduce the number of cache operations for dav operations
This commit is contained in:
commit
4d85ffc27c
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
namespace OCA\DAV\Connector\Sabre;
|
namespace OCA\DAV\Connector\Sabre;
|
||||||
|
|
||||||
|
use OC\Files\Node\Folder;
|
||||||
use OCA\DAV\Files\BrowserErrorPagePlugin;
|
use OCA\DAV\Files\BrowserErrorPagePlugin;
|
||||||
use OCP\Files\Mount\IMountManager;
|
use OCP\Files\Mount\IMountManager;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
|
@ -135,7 +136,11 @@ class ServerFactory {
|
||||||
|
|
||||||
/** @var \OC\Files\View $view */
|
/** @var \OC\Files\View $view */
|
||||||
$view = $viewCallBack($server);
|
$view = $viewCallBack($server);
|
||||||
|
if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) {
|
||||||
|
$rootInfo = $userFolder;
|
||||||
|
} else {
|
||||||
$rootInfo = $view->getFileInfo('');
|
$rootInfo = $view->getFileInfo('');
|
||||||
|
}
|
||||||
|
|
||||||
// Create ownCloud Dir
|
// Create ownCloud Dir
|
||||||
if ($rootInfo->getType() === 'dir') {
|
if ($rootInfo->getType() === 'dir') {
|
||||||
|
|
|
@ -41,6 +41,7 @@ class MountPoint implements IMountPoint {
|
||||||
protected $storage = null;
|
protected $storage = null;
|
||||||
protected $class;
|
protected $class;
|
||||||
protected $storageId;
|
protected $storageId;
|
||||||
|
protected $rootId = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration options for the storage backend
|
* Configuration options for the storage backend
|
||||||
|
@ -264,7 +265,10 @@ class MountPoint implements IMountPoint {
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getStorageRootId() {
|
public function getStorageRootId() {
|
||||||
return (int)$this->getStorage()->getCache()->getId('');
|
if (is_null($this->rootId)) {
|
||||||
|
$this->rootId = (int)$this->getStorage()->getCache()->getId('');
|
||||||
|
}
|
||||||
|
return $this->rootId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMountId() {
|
public function getMountId() {
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
namespace OC\Files\Node;
|
namespace OC\Files\Node;
|
||||||
|
|
||||||
|
use OC\Cache\CappedMemoryCache;
|
||||||
use OC\Files\Mount\Manager;
|
use OC\Files\Mount\Manager;
|
||||||
use OC\Files\Mount\MountPoint;
|
use OC\Files\Mount\MountPoint;
|
||||||
use OCP\Files\NotFoundException;
|
use OCP\Files\NotFoundException;
|
||||||
|
@ -71,6 +72,8 @@ class Root extends Folder implements IRootFolder {
|
||||||
*/
|
*/
|
||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
|
private $userFolderCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \OC\Files\Mount\Manager $manager
|
* @param \OC\Files\Mount\Manager $manager
|
||||||
* @param \OC\Files\View $view
|
* @param \OC\Files\View $view
|
||||||
|
@ -81,6 +84,7 @@ class Root extends Folder implements IRootFolder {
|
||||||
$this->mountManager = $manager;
|
$this->mountManager = $manager;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$this->emitter = new PublicEmitter();
|
$this->emitter = new PublicEmitter();
|
||||||
|
$this->userFolderCache = new CappedMemoryCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -335,25 +339,26 @@ class Root extends Folder implements IRootFolder {
|
||||||
* @return \OCP\Files\Folder
|
* @return \OCP\Files\Folder
|
||||||
*/
|
*/
|
||||||
public function getUserFolder($userId) {
|
public function getUserFolder($userId) {
|
||||||
|
if (!$this->userFolderCache->hasKey($userId)) {
|
||||||
\OC\Files\Filesystem::initMountPoints($userId);
|
\OC\Files\Filesystem::initMountPoints($userId);
|
||||||
$dir = '/' . $userId;
|
|
||||||
$folder = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$folder = $this->get($dir);
|
$folder = $this->get('/' . $userId . '/files');
|
||||||
} catch (NotFoundException $e) {
|
} catch (NotFoundException $e) {
|
||||||
$folder = $this->newFolder($dir);
|
if (!$this->nodeExists('/' . $userId)) {
|
||||||
|
$this->newFolder('/' . $userId);
|
||||||
}
|
}
|
||||||
|
$folder = $this->newFolder('/' . $userId . '/files');
|
||||||
$dir = '/files';
|
|
||||||
try {
|
|
||||||
$folder = $folder->get($dir);
|
|
||||||
} catch (NotFoundException $e) {
|
|
||||||
$folder = $folder->newFolder($dir);
|
|
||||||
\OC_Util::copySkeleton($userId, $folder);
|
\OC_Util::copySkeleton($userId, $folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $folder;
|
$this->userFolderCache->set($userId, $folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->userFolderCache->get($userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clearCache() {
|
||||||
|
$this->userFolderCache = new CappedMemoryCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -356,6 +356,7 @@ class OC_Util {
|
||||||
*/
|
*/
|
||||||
public static function tearDownFS() {
|
public static function tearDownFS() {
|
||||||
\OC\Files\Filesystem::tearDown();
|
\OC\Files\Filesystem::tearDown();
|
||||||
|
\OC::$server->getRootFolder()->clearCache();
|
||||||
self::$fsSetup = false;
|
self::$fsSetup = false;
|
||||||
self::$rootMounted = false;
|
self::$rootMounted = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ namespace Test;
|
||||||
|
|
||||||
use DOMDocument;
|
use DOMDocument;
|
||||||
use DOMNode;
|
use DOMNode;
|
||||||
|
use OC\Cache\CappedMemoryCache;
|
||||||
use OC\Command\QueueBus;
|
use OC\Command\QueueBus;
|
||||||
use OC\Files\Filesystem;
|
use OC\Files\Filesystem;
|
||||||
use OC\Template\Base;
|
use OC\Template\Base;
|
||||||
|
|
Loading…
Reference in New Issue