@@ -119,25 +119,29 @@ public function clearBackends(): void {
119119 }
120120
121121 /**
122- * get a user by user id
123- *
124- * @param string $uid
125- * @return User|null Either the user or null if the specified user does not exist
122+ * {@inheritDoc}
123+ * @param list<string> $excludeBackends A list of IUserBackend::getBackendName() that need to be excluded from the search.
126124 */
127125 #[\Override]
128- public function get ($ uid) {
129- if (is_null ( $ uid) || $ uid === '' || $ uid === false ) {
126+ public function get (string $ uid, array $ excludeBackends = []): \ OCP \ IUser | null {
127+ if ($ uid === '' ) {
130128 return null ;
131129 }
132- if (isset ($ this ->cachedUsers [$ uid ])) { //check the cache first to prevent having to loop over the backends
133- return $ this ->cachedUsers [$ uid ];
134- }
135130
136131 if (strlen ($ uid ) > IUser::MAX_USERID_LENGTH ) {
137132 return null ;
138133 }
139134
135+ // check the cache first to prevent having to loop over the backends
136+ if ($ excludeBackends === [] && isset ($ this ->cachedUsers [$ uid ])) {
137+ return $ this ->cachedUsers [$ uid ];
138+ }
139+
140140 $ cachedBackend = $ this ->cache ->get (sha1 ($ uid ));
141+ if (in_array ($ cachedBackend , $ excludeBackends )) {
142+ $ cachedBackend = null ;
143+ }
144+
141145 if ($ cachedBackend !== null && isset ($ this ->backends [$ cachedBackend ])) {
142146 // Cache has the info of the user backend already, so ask that one directly
143147 $ backend = $ this ->backends [$ cachedBackend ];
@@ -152,6 +156,10 @@ public function get($uid) {
152156 continue ;
153157 }
154158
159+ if (in_array ($ i , $ excludeBackends )) {
160+ continue ;
161+ }
162+
155163 if ($ backend ->userExists ($ uid )) {
156164 // Hash $uid to ensure that only valid characters are used for the cache key
157165 $ this ->cache ->set (sha1 ($ uid ), $ i , 300 );
@@ -194,19 +202,13 @@ public function getUserObject($uid, $backend, $cacheUser = true) {
194202 return $ user ;
195203 }
196204
197- /**
198- * check if a user exists
199- *
200- * @param string $uid
201- * @return bool
202- */
203205 #[\Override]
204- public function userExists ($ uid) {
206+ public function userExists (string $ uid, array $ excludeBackends = []): bool {
205207 if (strlen ($ uid ) > IUser::MAX_USERID_LENGTH ) {
206208 return false ;
207209 }
208210
209- $ user = $ this ->get ($ uid );
211+ $ user = $ this ->get ($ uid, $ excludeBackends );
210212 return ($ user !== null );
211213 }
212214
0 commit comments