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

In reply to Catalyst, LDAP User Auto_complete and arrays with grep by ghenry

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.