Skip to content

Commit

Permalink
Cap LDAP user cache (#25323)
Browse files Browse the repository at this point in the history
  • Loading branch information
butonic authored and DeepDiver1975 committed Jul 4, 2016
1 parent 59fc3ff commit 6b4b337
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions apps/user_ldap/lib/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -93,6 +93,8 @@ public function __construct(IConfig $ocConfig,
$this->image = $image;
$this->db = $db;
$this->userManager = $userManager;
$this->usersByDN = new CappedMemoryCache();
$this->usersByUid = new CappedMemoryCache();
}

/**
Expand All @@ -116,8 +118,8 @@ private function createAndCache($dn, $uid) {
$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;
}

Expand Down Expand Up @@ -219,10 +221,10 @@ protected function createInstancyByUserName($id) {
*/
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) ) {
Expand Down

0 comments on commit 6b4b337

Please sign in to comment.