[Rt-commit] rt branch, 4.2/do-not-search-without-term-in-user-search, created. rt-4.2.1-191-gd34f402
? sunnavy
sunnavy at bestpractical.com
Thu Jan 9 10:30:47 EST 2014
The branch, 4.2/do-not-search-without-term-in-user-search has been created
at d34f402f5f0a7919c611d3f289b56f861267edb9 (commit)
- Log -----------------------------------------------------------------
commit d34f402f5f0a7919c611d3f289b56f861267edb9
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Jan 9 22:57:05 2014 +0800
don't bother searching users at all without search term
without this, the page could hang(query could take a lot of time) if users
number is huge. (I got bitten with 700,000 users before)
technically, when there is no $UserString, though RT::Users::SimpleSearch
directly returns, the following $users calls like "$users->First", etc will
still query the db, which is both time-consuming and unnecessary in this case.
diff --git a/share/html/User/Search.html b/share/html/User/Search.html
index 282f243..3c1e711 100644
--- a/share/html/User/Search.html
+++ b/share/html/User/Search.html
@@ -75,20 +75,21 @@
<%INIT>
-my $exclude = [RT->Nobody->Id, RT->System->Id];
-my $users = RT::Users->new($session{'CurrentUser'});
-$users->SimpleSearch( Return => 'Name',
- Term => $UserString,
- Max => 100,
- Exclude => $exclude );
-
-my $first = $users->First;
-RT::Interface::Web::Redirect(RT->Config->Get('WebURL')."User/Summary.html?id=".$first->Id)
- if $users->Count == 1;
-
-$users->GotoFirstItem;
-
-my $Format = RT->Config->Get('UserSearchResultFormat');
+my $users;
+my $Format;
+if ( $UserString ) {
+ my $exclude = [RT->Nobody->Id, RT->System->Id];
+ $users = RT::Users->new($session{'CurrentUser'});
+ $users->SimpleSearch( Return => 'Name',
+ Term => $UserString,
+ Max => 100,
+ Exclude => $exclude );
+ my $first = $users->First;
+ RT::Interface::Web::Redirect(RT->Config->Get('WebURL')."User/Summary.html?id=".$first->Id)
+ if $users->Count == 1;
+ $users->GotoFirstItem;
+ $Format = RT->Config->Get('UserSearchResultFormat');
+}
my $search_fields = join ", ",
sort map {s/^CF\.(?:\{(.*)}|(.*))/$1 || $2/e; loc($_)}
-----------------------------------------------------------------------
More information about the rt-commit
mailing list