Dear Master Monks,
I am unsure why I can't pass @founds_users straight to my auto_complete prototype function, but need to copy it first?
Also, any advice on caching the LDAP searches? LDAP is so fast and our indexes are all active, that I don't think it's necessary, but maybe on a Directory of 500,000 - 1,000,000 users?
Any advice on handling an array of this size if the LDAP search returns "many" users?
sub suggest_ldap_user : Local {
my ($self, $c) = @_;
$c->stash->{template} = "resetuser.tt";
my $tabs = "\t\t\t\t\t\t";
$c->log->debug(
"Reading config:",
"$tabs". $c->config->{base},
"$tabs". $c->config->{scope},
"$tabs". $c->config->{user_filter},
"$tabs". $c->config->{attrs},
);
# Search for the LDAP users and stick them in @users
my $search =
$c->model('User')->search(
base => $c->config->{base},
scope => $c->config->{scope},
filter => $c->config->{user_filter
+},
attrs => [$c->config->{attrs}],
);
my @users = $search->entries;
$c->log->debug(
"Checking first entry in search result array:",
"$tabs". $users[0]->get_value('uid'),
);
for my $user ( @users ) {
for my $uid ( $user->attributes ) {
# We don't want workstations, or the nobody user
# (they have $ on end of name)
my $ldap_user = $user->get_value( $uid );
next if ( $ldap_user =~ /\$$/ );
next if ( $ldap_user =~ /^nobody/ );
push @{$c->stash->{'users'}}, $ldap_user;
}
}
# Grab the search term
my $req = $c->req->param('ldap_user');
$c->log->debug();
$c->log->debug( "Search term to auto_complete is $req");
$c->log->debug();
$c->log->debug( "Looking through these users: @{$c->stash->{'users
+'}}" );
# Only return users that start with the above letter
my @found_users = grep { /^$req/ } @{$c->stash->{'users'}};
$c->log->debug( "Found user/s @found_users as per your search.
Sending results.." );
$c->log->debug();
# Only works this way and not by just passing @found_users?
my @ldap_users = @found_users;
# Send results
$c->res->output( $c->prototype->auto_complete_result(\@ldap_users)
+ );
}
Walking the road to enlightenment... I found a penguin and a camel on the way.....
Fancy a yourname@perl.me.uk? Just ask!!!