3131use OCP \Group \Backend \ICountUsersBackend ;
3232use OCP \Group \Backend \IGroupDetailsBackend ;
3333use OCP \Group \Backend \IIsAdminBackend ;
34+ use OCP \Group \Backend \ISearchableGroupBackend ;
3435use OCP \ILogger ;
36+ use OCP \IUserManager ;
37+
38+ use OC \User \LazyUser ;
3539
3640/**
3741 * The SQL group backend manager.
4145final class GroupBackend extends ABackend implements
4246 ICountUsersBackend,
4347 IGroupDetailsBackend,
44- IIsAdminBackend
48+ IIsAdminBackend,
49+ ISearchableGroupBackend
4550{
4651 const USER_SQL_GID = "user_sql " ;
4752
@@ -354,16 +359,16 @@ public function usersInGroup($gid, $search = "", $limit = -1, $offset = 0)
354359 ["app " => $ this ->appName ]
355360 );
356361
357- $ cacheKey = self ::class . "group_users_ " . $ gid . "_ " . $ search . "_ "
362+ $ cacheKey = self ::class . "group_uids_ " . $ gid . "_ " . $ search . "_ "
358363 . $ limit . "_ " . $ offset ;
359- $ users = $ this ->cache ->get ($ cacheKey );
364+ $ uids = $ this ->cache ->get ($ cacheKey );
360365
361- if (!is_null ($ users )) {
366+ if (!is_null ($ uids )) {
362367 $ this ->logger ->debug (
363368 "Returning from cache usersInGroup( $ gid, $ search, $ limit, $ offset): count( "
364- . count ($ users ) . ") " , ["app " => $ this ->appName ]
369+ . count ($ uids ) . ") " , ["app " => $ this ->appName ]
365370 );
366- return $ users ;
371+ return $ uids ;
367372 }
368373
369374 $ uids = $ this ->groupRepository ->findAllUidsBySearchTerm (
@@ -383,6 +388,50 @@ public function usersInGroup($gid, $search = "", $limit = -1, $offset = 0)
383388 return $ uids ;
384389 }
385390
391+ /**
392+ * @inheritdoc
393+ */
394+ public function searchInGroup (string $ gid , string $ search = '' , int $ limit = -1 , int $ offset = 0 ): array
395+ {
396+ $ this ->logger ->debug (
397+ "Entering searchInGroup( $ gid, $ search, $ limit, $ offset) " ,
398+ ["app " => $ this ->appName ]
399+ );
400+
401+ $ cacheKey = self ::class . "group_users_ " . $ gid . "_ " . $ search . "_ "
402+ . $ limit . "_ " . $ offset ;
403+ $ names = $ this ->cache ->get ($ cacheKey );
404+
405+ if ($ names === null ) {
406+ $ names = $ this ->groupRepository ->findAllUsersBySearchTerm (
407+ $ this ->substituteGid ($ gid ), "% " . $ search . "% " , $ limit , $ offset
408+ );
409+
410+ if ($ names === false ) {
411+ return [];
412+ }
413+
414+ $ this ->cache ->set ($ cacheKey , $ names );
415+ $ this ->logger ->debug (
416+ "Using from DB searchInGroup( $ gid, $ search, $ limit, $ offset): count( "
417+ . count ($ names ) . ") " , ["app " => $ this ->appName ]
418+ );
419+ } else {
420+ $ this ->logger ->debug (
421+ "Using from cache searchInGroup( $ gid, $ search, $ limit, $ offset): count( "
422+ . count ($ names ) . ") " , ["app " => $ this ->appName ]
423+ );
424+ }
425+
426+ $ users = [];
427+ $ userManager = \OCP \Server::get (IUserManager::class);
428+ foreach ($ names as $ uid => $ name ) {
429+ $ users [$ uid ] = new LazyUser ($ uid , $ userManager , $ name );
430+ }
431+
432+ return $ users ;
433+ }
434+
386435 /**
387436 * @inheritdoc
388437 */
0 commit comments