Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Catalyst, LDAP User Auto_complete and arrays with grep

by ghenry (Vicar)
on Mar 31, 2006 at 08:48 UTC ( [id://540413]=perlquestion: print w/replies, xml ) Need Help??

ghenry has asked for the wisdom of the Perl Monks concerning the following question:

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!!!

Replies are listed 'Best First'.
Re: Catalyst, LDAP User Auto_complete and arrays with grep
by aquarium (Curate) on Mar 31, 2006 at 13:41 UTC
    your auto_complete_result function is taking a reference to @ldap_users array....so it should also work by passing a reference to @found_users, without the needless array copy...like so
    $c->res->output( $c->prototype->auto_complete_result(\@found_users));
    the hardest line to type correctly is: stty erase ^H

      It doesn't ;-)

      That's what I was asking.

      If I swap @found_users back to @ldap_users without the copy, nothing appears, only with the copy. If I don't use grep and just leave the array as is, it works fine. Just with no filtering.

      I don't know why....

      Walking the road to enlightenment... I found a penguin and a camel on the way.....
      Fancy a yourname@perl.me.uk? Just ask!!!
Re: Catalyst, LDAP User Auto_complete and arrays with grep
by bluto (Curate) on Apr 04, 2006 at 17:55 UTC
    Any advice on handling an array of this size if the LDAP search returns "many" users?

    Will the "callback" option of Net::LDAP's search method help? It will allow you to handle the entries one at a time as they are returned. You can build an array, or even serialize them to disk if find out the array is getting large. If you must keep a large number of entries in memory then it may not be worth it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://540413]
Approved by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-03-29 12:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found