Cap LDAP user cache (#25323)

This commit is contained in:
Jörn Friedrich Dreyer 2016-07-04 13:57:15 +02:00 committed by Thomas Müller
parent 9e0d8fcf41
commit d2d2a75529
1 changed files with 15 additions and 13 deletions

View File

@ -25,6 +25,7 @@
namespace OCA\User_LDAP\User;
use OC\Cache\CappedMemoryCache;
use OCA\User_LDAP\LogWrapper;
use OCA\User_LDAP\FilesystemHelper;
use OCP\IAvatarManager;
@ -62,14 +63,13 @@ class Manager {
protected $avatarManager;
/**
* array['byDN'] \OCA\User_LDAP\User\User[]
* ['byUid'] \OCA\User_LDAP\User\User[]
* @var array $users
* @var CappedMemoryCache $usersByDN
*/
protected $users = array(
'byDN' => array(),
'byUid' => array(),
);
protected $usersByDN;
/**
* @var CappedMemoryCache $usersByUid
*/
protected $usersByUid;
/**
* @param IConfig $ocConfig
@ -93,6 +93,8 @@ class Manager {
$this->image = $image;
$this->db = $db;
$this->userManager = $userManager;
$this->usersByDN = new CappedMemoryCache();
$this->usersByUid = new CappedMemoryCache();
}
/**
@ -116,8 +118,8 @@ class Manager {
$user = new User($uid, $dn, $this->access, $this->ocConfig,
$this->ocFilesystem, clone $this->image, $this->ocLog,
$this->avatarManager, $this->userManager);
$this->users['byDN'][$dn] = $user;
$this->users['byUid'][$uid] = $user;
$this->usersByDN[$dn] = $user;
$this->usersByUid[$uid] = $user;
return $user;
}
@ -219,10 +221,10 @@ class Manager {
*/
public function get($id) {
$this->checkAccess();
if(isset($this->users['byDN'][$id])) {
return $this->users['byDN'][$id];
} else if(isset($this->users['byUid'][$id])) {
return $this->users['byUid'][$id];
if(isset($this->usersByDN[$id])) {
return $this->usersByDN[$id];
} else if(isset($this->usersByUid[$id])) {
return $this->usersByUid[$id];
}
if($this->access->stringResemblesDN($id) ) {