@@ -126,19 +126,25 @@ public function clearBackends() {
126126 * @param string $uid
127127 * @return \OC\User\User|null Either the user or null if the specified user does not exist
128128 */
129- public function get ($ uid ) {
129+ public function get ($ uid, array $ excludeBackends = [] ) {
130130 if (is_null ($ uid ) || $ uid === '' || $ uid === false ) {
131131 return null ;
132132 }
133- if (isset ($ this ->cachedUsers [$ uid ])) { //check the cache first to prevent having to loop over the backends
134- return $ this ->cachedUsers [$ uid ];
135- }
136133
137134 if (strlen ($ uid ) > self ::MAX_USERID_LENGTH ) {
138135 return null ;
139136 }
140137
138+ // check the cache first to prevent having to loop over the backends
139+ if ($ excludeBackends === [] && isset ($ this ->cachedUsers [$ uid ])) {
140+ return $ this ->cachedUsers [$ uid ];
141+ }
142+
141143 $ cachedBackend = $ this ->cache ->get (sha1 ($ uid ));
144+ if (in_array ($ cachedBackend , $ excludeBackends )) {
145+ $ cachedBackend = null ;
146+ }
147+
142148 if ($ cachedBackend !== null && isset ($ this ->backends [$ cachedBackend ])) {
143149 // Cache has the info of the user backend already, so ask that one directly
144150 $ backend = $ this ->backends [$ cachedBackend ];
@@ -153,6 +159,10 @@ public function get($uid) {
153159 continue ;
154160 }
155161
162+ if (in_array ($ i , $ excludeBackends )) {
163+ continue ;
164+ }
165+
156166 if ($ backend ->userExists ($ uid )) {
157167 // Hash $uid to ensure that only valid characters are used for the cache key
158168 $ this ->cache ->set (sha1 ($ uid ), $ i , 300 );
@@ -196,12 +206,12 @@ public function getUserObject($uid, $backend, $cacheUser = true) {
196206 * @param string $uid
197207 * @return bool
198208 */
199- public function userExists ($ uid ) {
209+ public function userExists ($ uid, array $ excludeBackends = [] ) {
200210 if (strlen ($ uid ) > self ::MAX_USERID_LENGTH ) {
201211 return false ;
202212 }
203213
204- $ user = $ this ->get ($ uid );
214+ $ user = $ this ->get ($ uid, $ excludeBackends );
205215 return ($ user !== null );
206216 }
207217
0 commit comments