From b066c0ff4480c3054630cdd846eda0043ee41d52 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon <blizzz@owncloud.com>
Date: Tue, 23 Apr 2013 01:00:27 +0200
Subject: [PATCH] LDAP: reset user/group-config association only after
 exists-check, may performance in some cases

---
 apps/user_ldap/group_proxy.php | 11 +++++++++--
 apps/user_ldap/user_proxy.php  | 11 +++++++++--
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/apps/user_ldap/group_proxy.php b/apps/user_ldap/group_proxy.php
index 68d2efe387..75e7cd4633 100644
--- a/apps/user_ldap/group_proxy.php
+++ b/apps/user_ldap/group_proxy.php
@@ -76,8 +76,15 @@ class Group_Proxy extends lib\Proxy implements \OCP\GroupInterface {
 			if(isset($this->backends[$prefix])) {
 				$result = call_user_func_array(array($this->backends[$prefix], $method), $parameters);
 				if(!$result) {
-					//not found here, reset cache to null
-					$this->writeToCache($cacheKey, null);
+					//not found here, reset cache to null if group vanished
+					//because sometimes methods return false with a reason
+					$groupExists = call_user_func_array(
+						array($this->backends[$prefix], 'groupExists'),
+						array($gid)
+					);
+					if(!$groupExists) {
+						$this->writeToCache($cacheKey, null);
+					}
 				}
 				return $result;
 			}
diff --git a/apps/user_ldap/user_proxy.php b/apps/user_ldap/user_proxy.php
index 6a75bae381..7e5b9045df 100644
--- a/apps/user_ldap/user_proxy.php
+++ b/apps/user_ldap/user_proxy.php
@@ -76,8 +76,15 @@ class User_Proxy extends lib\Proxy implements \OCP\UserInterface {
 			if(isset($this->backends[$prefix])) {
 				$result = call_user_func_array(array($this->backends[$prefix], $method), $parameters);
 				if(!$result) {
-					//not found here, reset cache to null
-					$this->writeToCache($cacheKey, null);
+					//not found here, reset cache to null if user vanished
+					//because sometimes methods return false with a reason
+					$userExists = call_user_func_array(
+						array($this->backends[$prefix], 'userExists'),
+						array($uid)
+					);
+					if(!$userExists) {
+						$this->writeToCache($cacheKey, null);
+					}
 				}
 				return $result;
 			}
-- 
GitLab