Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the number of cache operations for dav operations #1054

Merged
merged 4 commits into from
Aug 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/dav/lib/Connector/Sabre/ServerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

namespace OCA\DAV\Connector\Sabre;

use OC\Files\Node\Folder;
use OCA\DAV\Files\BrowserErrorPagePlugin;
use OCP\Files\Mount\IMountManager;
use OCP\IConfig;
Expand Down Expand Up @@ -135,7 +136,11 @@ public function createServer($baseUri,

/** @var \OC\Files\View $view */
$view = $viewCallBack($server);
$rootInfo = $view->getFileInfo('');
if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) {
$rootInfo = $userFolder;
} else {
$rootInfo = $view->getFileInfo('');
}

// Create ownCloud Dir
if ($rootInfo->getType() === 'dir') {
Expand Down
6 changes: 5 additions & 1 deletion lib/private/Files/Mount/MountPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class MountPoint implements IMountPoint {
protected $storage = null;
protected $class;
protected $storageId;
protected $rootId = null;

/**
* Configuration options for the storage backend
Expand Down Expand Up @@ -264,7 +265,10 @@ public function getOptions() {
* @return int
*/
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() {
Expand Down
37 changes: 21 additions & 16 deletions lib/private/Files/Node/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

namespace OC\Files\Node;

use OC\Cache\CappedMemoryCache;
use OC\Files\Mount\Manager;
use OC\Files\Mount\MountPoint;
use OCP\Files\NotFoundException;
Expand Down Expand Up @@ -71,6 +72,8 @@ class Root extends Folder implements IRootFolder {
*/
private $user;

private $userFolderCache;

/**
* @param \OC\Files\Mount\Manager $manager
* @param \OC\Files\View $view
Expand All @@ -81,6 +84,7 @@ public function __construct($manager, $view, $user) {
$this->mountManager = $manager;
$this->user = $user;
$this->emitter = new PublicEmitter();
$this->userFolderCache = new CappedMemoryCache();
}

/**
Expand Down Expand Up @@ -335,25 +339,26 @@ public function getName() {
* @return \OCP\Files\Folder
*/
public function getUserFolder($userId) {
\OC\Files\Filesystem::initMountPoints($userId);
$dir = '/' . $userId;
$folder = null;

try {
$folder = $this->get($dir);
} catch (NotFoundException $e) {
$folder = $this->newFolder($dir);
}
if (!$this->userFolderCache->hasKey($userId)) {
\OC\Files\Filesystem::initMountPoints($userId);

try {
$folder = $this->get('/' . $userId . '/files');
} catch (NotFoundException $e) {
if (!$this->nodeExists('/' . $userId)) {
$this->newFolder('/' . $userId);
}
$folder = $this->newFolder('/' . $userId . '/files');
\OC_Util::copySkeleton($userId, $folder);
}

$dir = '/files';
try {
$folder = $folder->get($dir);
} catch (NotFoundException $e) {
$folder = $folder->newFolder($dir);
\OC_Util::copySkeleton($userId, $folder);
$this->userFolderCache->set($userId, $folder);
}

return $folder;
return $this->userFolderCache->get($userId);
}

public function clearCache() {
$this->userFolderCache = new CappedMemoryCache();
}
}
1 change: 1 addition & 0 deletions lib/private/legacy/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ public static function copyr($source, \OCP\Files\Folder $target) {
*/
public static function tearDownFS() {
\OC\Files\Filesystem::tearDown();
\OC::$server->getRootFolder()->clearCache();
self::$fsSetup = false;
self::$rootMounted = false;
}
Expand Down
1 change: 1 addition & 0 deletions tests/lib/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use DOMDocument;
use DOMNode;
use OC\Cache\CappedMemoryCache;
use OC\Command\QueueBus;
use OC\Files\Filesystem;
use OC\Template\Base;
Expand Down