Browse Source

multiple minor fies

tags/v9.0beta1
Robin Appelman 8 years ago
parent
commit
99415a9f7f

+ 3
- 1
lib/private/files/config/mountprovidercollection.php View File

@@ -93,11 +93,13 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
* @param IUser $user
* @param IMountPoint[] $mountPoints
*/
public function cacheMounts(IUser $user, array $mountPoints) {
public function registerMounts(IUser $user, array $mountPoints) {
$this->mountCache->registerMounts($user, $mountPoints);
}

/**
* Get the mount cache which can be used to search for mounts without setting up the filesystem
*
* @return IUserMountCache
*/
public function getMountCache() {

+ 20
- 9
lib/private/files/config/usermountcache.php View File

@@ -31,6 +31,9 @@ use OCP\ILogger;
use OCP\IUser;
use OCP\IUserManager;

/**
* Cache mounts points per user in the cache so we can easilly look them up
*/
class UserMountCache implements IUserMountCache {
/**
* @var IDBConnection
@@ -64,15 +67,16 @@ class UserMountCache implements IUserMountCache {
}

public function registerMounts(IUser $user, array $mounts) {
// filter out non-proper storages coming from unit tests
$mounts = array_filter($mounts, function (IMountPoint $mount) {
return $mount->getStorage()->getCache();
});
$mounts = array_values($mounts);
/** @var ICachedMountInfo[] $newMounts */
$newMounts = array_map(function (IMountPoint $mount) use ($user) {
$storage = $mount->getStorage();
$rootId = (int)$storage->getCache()->getId('');
$storageId = (int)$storage->getStorageCache()->getNumericId();
// filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet)
if ($rootId === -1) {
return null;
} else {
@@ -80,9 +84,10 @@ class UserMountCache implements IUserMountCache {
}
}, $mounts);
$newMounts = array_values(array_filter($newMounts));
$cachedMounts = $this->getMountsForUser($user);

$cachedMounts = $this->getMountsForUser($user);
$mountDiff = function (ICachedMountInfo $mount1, ICachedMountInfo $mount2) {
// since we are only looking for mounts for a specific user comparing on root id is enough
return $mount1->getRootId() - $mount2->getRootId();
};

@@ -97,7 +102,8 @@ class UserMountCache implements IUserMountCache {
}
foreach ($removedMounts as $mount) {
$this->removeFromCache($mount);
$this->mountsForUsers[$user->getUID()] = [];
$index = array_search($mount, $this->mountsForUsers[$user->getUID()]);
unset($this->mountsForUsers[$user->getUID()][$index]);
}
}

@@ -121,6 +127,8 @@ class UserMountCache implements IUserMountCache {
$query->execute();
} catch (UniqueConstraintViolationException $e) {
// seems to mainly happen in tests
// can also happen during concurrent access but we can safely ignore it
// since inserting the same data twice will still result in the correct data being inserted
$this->logger->error('Duplicate entry while inserting mount');
$this->logger->logException($e);
}
@@ -145,14 +153,17 @@ class UserMountCache implements IUserMountCache {
* @return ICachedMountInfo[]
*/
public function getMountsForUser(IUser $user) {
$builder = $this->connection->getQueryBuilder();
$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point')
->from('mounts')
->where($builder->expr()->eq('user_id', $builder->createPositionalParameter($user->getUID())));
if (!isset($this->mountsForUsers[$user->getUID()])) {
$builder = $this->connection->getQueryBuilder();
$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point')
->from('mounts')
->where($builder->expr()->eq('user_id', $builder->createPositionalParameter($user->getUID())));

$rows = $query->execute()->fetchAll();
$rows = $query->execute()->fetchAll();

return array_map([$this, 'dbRowToMountInfo'], $rows);
$this->mountsForUsers[$user->getUID()] = array_map([$this, 'dbRowToMountInfo'], $rows);
}
return $this->mountsForUsers[$user->getUID()];
}

/**

+ 1
- 1
lib/private/files/filesystem.php View File

@@ -428,7 +428,7 @@ class Filesystem {
$mounts = $mountConfigManager->getMountsForUser($userObject);
array_walk($mounts, array(self::$mounts, 'addMount'));
$mounts[] = $mount;
$mountConfigManager->cacheMounts($userObject, $mounts);
$mountConfigManager->registerMounts($userObject, $mounts);
}

self::listenForNewMountProviders($mountConfigManager, $userManager);

+ 2
- 0
lib/public/files/config/icachedmountinfo.php View File

@@ -25,6 +25,8 @@ use OCP\Files\Node;
use OCP\IUser;

/**
* Holds information about a mount for a user
*
* @since 9.0.0
*/
interface ICachedMountInfo {

+ 8
- 0
lib/public/files/config/imountprovidercollection.php View File

@@ -46,4 +46,12 @@ interface IMountProviderCollection {
* @since 8.0.0
*/
public function registerProvider(IMountProvider $provider);

/**
* Get the mount cache which can be used to search for mounts without setting up the filesystem
*
* @return IUserMountCache
* @since 9.0.0
*/
public function getMountCache();
}

+ 2
- 0
lib/public/files/config/iusermountcache.php View File

@@ -25,6 +25,8 @@ use OCP\Files\Mount\IMountPoint;
use OCP\IUser;

/**
* Cache mounts points per user in the cache so we can easily look them up
*
* @since 9.0.0
*/
interface IUserMountCache {

+ 1
- 11
tests/lib/files/config/usermountcache.php View File

@@ -18,16 +18,6 @@ use OCP\IUserManager;
use Test\TestCase;
use Test\Util\User\Dummy;

class NullLogger extends Log {
public function __construct($logger = null) {
//disable original constructor
}

public function log($level, $message, array $context = array()) {
//noop
}
}

/**
* @group DB
*/
@@ -54,7 +44,7 @@ class UserMountCache extends TestCase {
$userBackend->createUser('u1', '');
$userBackend->createUser('u2', '');
$this->userManager->registerBackend($userBackend);
$this->cache = new \OC\Files\Config\UserMountCache($this->connection, $this->userManager, new NullLogger());
$this->cache = new \OC\Files\Config\UserMountCache($this->connection, $this->userManager, $this->getMock('\OC\Log'));
}

public function tearDown() {

Loading…
Cancel
Save