Ver código fonte

Cap LDAP user cache (#25323)

Jörn Friedrich Dreyer 8 anos atrás
pai
commit
d2d2a75529
1 arquivos alterados com 15 adições e 13 exclusões
  1. 15 13
      apps/user_ldap/lib/User/Manager.php

+ 15 - 13
apps/user_ldap/lib/User/Manager.php

@@ -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) ) {