Skip to content

Commit

Permalink
cache user folders
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Aug 25, 2016
1 parent b2d3657 commit 2693ae8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
42 changes: 26 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,31 @@ 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);
$dir = '/' . $userId;
$folder = null;

try {
$folder = $this->get($dir);
} catch (NotFoundException $e) {
$folder = $this->newFolder($dir);
}

$dir = '/files';
try {
$folder = $folder->get($dir);
} catch (NotFoundException $e) {
$folder = $folder->newFolder($dir);
\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

0 comments on commit 2693ae8

Please sign in to comment.