mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 09:13:19 -04:00
log duplicates
This commit is contained in:
parent
f986fb99f2
commit
8940429976
3 changed files with 20 additions and 4 deletions
|
|
@ -21,11 +21,13 @@
|
|||
|
||||
namespace OC\Files\Config;
|
||||
|
||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||
use OCP\Files\Config\ICachedMountInfo;
|
||||
use OCP\Files\Config\IUserMountCache;
|
||||
use OCP\Files\Mount\IMountPoint;
|
||||
use OCP\ICache;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\ILogger;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
|
||||
|
|
@ -43,15 +45,22 @@ class UserMountCache implements IUserMountCache {
|
|||
/** @var ICachedMountInfo[][] [$userId => [$cachedMountInfo, ....], ...] */
|
||||
private $mountsForUsers = [];
|
||||
|
||||
/**
|
||||
* @var ILogger
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* UserMountCache constructor.
|
||||
*
|
||||
* @param IDBConnection $connection
|
||||
* @param IUserManager $userManager
|
||||
* @param ILogger $logger
|
||||
*/
|
||||
public function __construct(IDBConnection $connection, IUserManager $userManager) {
|
||||
public function __construct(IDBConnection $connection, IUserManager $userManager, ILogger $logger) {
|
||||
$this->connection = $connection;
|
||||
$this->userManager = $userManager;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function registerMounts(IUser $user, array $mounts) {
|
||||
|
|
@ -108,7 +117,13 @@ class UserMountCache implements IUserMountCache {
|
|||
':user' => $mount->getUser()->getUID(),
|
||||
':mount' => $mount->getMountPoint()
|
||||
]);
|
||||
$query->execute();
|
||||
try {
|
||||
$query->execute();
|
||||
} catch (UniqueConstraintViolationException $e) {
|
||||
// seems to mainly happen in tests
|
||||
$this->logger->error('Duplicate entry while inserting mount');
|
||||
$this->logger->logException($e);
|
||||
}
|
||||
}
|
||||
|
||||
private function removeFromCache(ICachedMountInfo $mount) {
|
||||
|
|
|
|||
|
|
@ -407,7 +407,7 @@ class Server extends ServerContainer implements IServerContainer {
|
|||
});
|
||||
$this->registerService('MountConfigManager', function (Server $c) {
|
||||
$loader = \OC\Files\Filesystem::getLoader();
|
||||
$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager());
|
||||
$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
|
||||
return new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
|
||||
});
|
||||
$this->registerService('IniWrapper', function ($c) {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ use OC\Files\Storage\Temporary;
|
|||
use OC\User\Manager;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IUserManager;
|
||||
use Test\NullLogger;
|
||||
use Test\TestCase;
|
||||
use Test\Util\User\Dummy;
|
||||
|
||||
|
|
@ -42,7 +43,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);
|
||||
$this->cache = new \OC\Files\Config\UserMountCache($this->connection, $this->userManager, new NullLogger());
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue