@@ -110,19 +110,25 @@ public function clearBackends(): void {
110110 * @param string $uid
111111 * @return \OC\User\User|null Either the user or null if the specified user does not exist
112112 */
113- public function get ($ uid ) {
113+ public function get ($ uid, array $ excludeBackends = [] ) {
114114 if (is_null ($ uid ) || $ uid === '' || $ uid === false ) {
115115 return null ;
116116 }
117- if (isset ($ this ->cachedUsers [$ uid ])) { //check the cache first to prevent having to loop over the backends
118- return $ this ->cachedUsers [$ uid ];
119- }
120117
121118 if (strlen ($ uid ) > IUser::MAX_USERID_LENGTH ) {
122119 return null ;
123120 }
124121
122+ // check the cache first to prevent having to loop over the backends
123+ if ($ excludeBackends === [] && isset ($ this ->cachedUsers [$ uid ])) {
124+ return $ this ->cachedUsers [$ uid ];
125+ }
126+
125127 $ cachedBackend = $ this ->cache ->get (sha1 ($ uid ));
128+ if (in_array ($ cachedBackend , $ excludeBackends )) {
129+ $ cachedBackend = null ;
130+ }
131+
126132 if ($ cachedBackend !== null && isset ($ this ->backends [$ cachedBackend ])) {
127133 // Cache has the info of the user backend already, so ask that one directly
128134 $ backend = $ this ->backends [$ cachedBackend ];
@@ -137,6 +143,10 @@ public function get($uid) {
137143 continue ;
138144 }
139145
146+ if (in_array ($ i , $ excludeBackends )) {
147+ continue ;
148+ }
149+
140150 if ($ backend ->userExists ($ uid )) {
141151 // Hash $uid to ensure that only valid characters are used for the cache key
142152 $ this ->cache ->set (sha1 ($ uid ), $ i , 300 );
@@ -180,12 +190,12 @@ public function getUserObject($uid, $backend, $cacheUser = true) {
180190 * @param string $uid
181191 * @return bool
182192 */
183- public function userExists ($ uid ) {
193+ public function userExists ($ uid, array $ excludeBackends = [] ) {
184194 if (strlen ($ uid ) > IUser::MAX_USERID_LENGTH ) {
185195 return false ;
186196 }
187197
188- $ user = $ this ->get ($ uid );
198+ $ user = $ this ->get ($ uid, $ excludeBackends );
189199 return ($ user !== null );
190200 }
191201
0 commit comments