@@ -118,25 +118,29 @@ public function clearBackends(): void {
118118 }
119119
120120 /**
121- * get a user by user id
122- *
123- * @param string $uid
124- * @return User|null Either the user or null if the specified user does not exist
121+ * {@inheritDoc}
122+ * @param list<string> $excludeBackends A list of IUserBackend::getBackendName() that need to be excluded from the search.
125123 */
126124 #[\Override]
127- public function get ($ uid) {
125+ public function get ($ uid, array $ excludeBackends = []): ? \ OCP \ IUser {
128126 if (is_null ($ uid ) || $ uid === '' || $ uid === false ) {
129127 return null ;
130128 }
131- if (isset ($ this ->cachedUsers [$ uid ])) { //check the cache first to prevent having to loop over the backends
132- return $ this ->cachedUsers [$ uid ];
133- }
134129
135130 if (strlen ($ uid ) > IUser::MAX_USERID_LENGTH ) {
136131 return null ;
137132 }
138133
134+ // check the cache first to prevent having to loop over the backends
135+ if ($ excludeBackends === [] && isset ($ this ->cachedUsers [$ uid ])) {
136+ return $ this ->cachedUsers [$ uid ];
137+ }
138+
139139 $ cachedBackend = $ this ->cache ->get (sha1 ($ uid ));
140+ if (in_array ($ cachedBackend , $ excludeBackends )) {
141+ $ cachedBackend = null ;
142+ }
143+
140144 if ($ cachedBackend !== null && isset ($ this ->backends [$ cachedBackend ])) {
141145 // Cache has the info of the user backend already, so ask that one directly
142146 $ backend = $ this ->backends [$ cachedBackend ];
@@ -151,6 +155,10 @@ public function get($uid) {
151155 continue ;
152156 }
153157
158+ if (in_array ($ i , $ excludeBackends )) {
159+ continue ;
160+ }
161+
154162 if ($ backend ->userExists ($ uid )) {
155163 // Hash $uid to ensure that only valid characters are used for the cache key
156164 $ this ->cache ->set (sha1 ($ uid ), $ i , 300 );
@@ -193,19 +201,13 @@ public function getUserObject($uid, $backend, $cacheUser = true) {
193201 return $ user ;
194202 }
195203
196- /**
197- * check if a user exists
198- *
199- * @param string $uid
200- * @return bool
201- */
202204 #[\Override]
203- public function userExists ($ uid) {
205+ public function userExists (string $ uid, array $ excludeBackends = []): bool {
204206 if (strlen ($ uid ) > IUser::MAX_USERID_LENGTH ) {
205207 return false ;
206208 }
207209
208- $ user = $ this ->get ($ uid );
210+ $ user = $ this ->get ($ uid, $ excludeBackends );
209211 return ($ user !== null );
210212 }
211213
0 commit comments