Best practice to count group members #512
-
Hi there! I need to count the members of several Active Directory groups. This is my code:
This works, but it's quite slow with >10 groups and >1500 members in each group. Is there a better (faster) way to achieve my goal? Thx! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @klepptor! I've just added a method for this in the latest v2.18.0 release. This method ( Here is how you can utilize this method: $group = Group::findByOrFail('distinguishedName', $groupDN);
$countOfMembers = $group->members()->count(); However, the fastest way would be to count the // Notice the last argument in the below method, asking the LDAP
// server to only return the "member" attribute, speeding
// up the query due to smaller response size:
$group = Group::findByOrFail('distinguishedName', $groupDN, 'member');
$countOfMembers = count($group['member']); |
Beta Was this translation helpful? Give feedback.
Hi @klepptor!
I've just added a method for this in the latest v2.18.0 release.
This method (
count()
) will execute a query on your LDAP server for all members the group, but restrict the query to only returnobjectclass
, trimming down the result size and speeding up the result.Here is how you can utilize this method:
However, the fastest way would be to count the
member
attribute on your resulting$group
model, if your server returns the full list (which may not be the case with larger groups):