From ea6b82f1303f86e5b62ea23985cc47cea5454f9b Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Tue, 5 Jul 2011 11:06:37 -0400 Subject: Bug 658929 - User autocomplete is very slow when there are lots of users in the profiles table r/a=mkanat --- Bugzilla/User.pm | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'Bugzilla/User.pm') diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm index 89cd7ce72..d21314604 100644 --- a/Bugzilla/User.pm +++ b/Bugzilla/User.pm @@ -82,6 +82,7 @@ use constant DEFAULT_USER => { 'showmybugslink' => 0, 'disabledtext' => '', 'disable_mail' => 0, + 'is_enabled' => 1, }; use constant DB_TABLE => 'profiles'; @@ -98,6 +99,7 @@ use constant DB_COLUMNS => ( 'profiles.disabledtext', 'profiles.disable_mail', 'profiles.extern_id', + 'profiles.is_enabled', ); use constant NAME_FIELD => 'login_name'; use constant ID_FIELD => 'userid'; @@ -110,6 +112,7 @@ use constant VALIDATORS => { login_name => \&check_login_name_for_creation, realname => \&_check_realname, extern_id => \&_check_extern_id, + is_enabled => \&_check_is_enabled, }; sub UPDATE_COLUMNS { @@ -120,11 +123,18 @@ sub UPDATE_COLUMNS { login_name realname extern_id + is_enabled ); push(@cols, 'cryptpassword') if exists $self->{cryptpassword}; return @cols; }; +use constant VALIDATOR_DEPENDENCIES => { + is_enabled => ['disabledtext'], +}; + +use constant EXTRA_REQUIRED_FIELDS => qw(is_enabled); + ################################################################################ # Functions ################################################################################ @@ -178,7 +188,7 @@ sub update { # XXX Can update profiles_activity here as soon as it understands # field names like login_name. - + return $changes; } @@ -238,11 +248,20 @@ sub _check_password { sub _check_realname { return trim($_[1]) || ''; } +sub _check_is_enabled { + my ($invocant, $is_enabled, undef, $params) = @_; + # is_enabled is set automatically on creation depending on whether + # disabledtext is empty (enabled) or not empty (disabled). + # When updating the user, is_enabled is set by calling set_disabledtext(). + # Any value passed into this validator is ignored. + my $disabledtext = ref($invocant) ? $invocant->disabledtext : $params->{disabledtext}; + return $disabledtext ? 0 : 1; +} + ################################################################################ # Mutators ################################################################################ -sub set_disabledtext { $_[0]->set('disabledtext', $_[1]); } sub set_disable_mail { $_[0]->set('disable_mail', $_[1]); } sub set_extern_id { $_[0]->set('extern_id', $_[1]); } @@ -261,6 +280,10 @@ sub set_name { sub set_password { $_[0]->set('cryptpassword', $_[1]); } +sub set_disabledtext { + $_[0]->set('disabledtext', $_[1]); + $_[0]->set('is_enabled', $_[1] ? 0 : 1); +} ################################################################################ # Methods @@ -272,7 +295,7 @@ sub login { $_[0]->{login_name}; } sub extern_id { $_[0]->{extern_id}; } sub email { $_[0]->login . Bugzilla->params->{'emailsuffix'}; } sub disabledtext { $_[0]->{'disabledtext'}; } -sub is_disabled { $_[0]->disabledtext ? 1 : 0; } +sub is_enabled { $_[0]->{'is_enabled'} ? 1 : 0; } sub showmybugslink { $_[0]->{showmybugslink}; } sub email_disabled { $_[0]->{disable_mail}; } sub email_enabled { !($_[0]->{disable_mail}); } @@ -1341,7 +1364,7 @@ sub match { "AND group_id IN(" . join(', ', (-1, @{$user->visible_groups_inherited})) . ") "; } - $query .= " AND disabledtext = '' " if $exclude_disabled; + $query .= " AND is_enabled = 1 " if $exclude_disabled; $query .= $dbh->sql_limit($limit) if $limit; # Execute the query, retrieve the results, and make them into @@ -1376,7 +1399,7 @@ sub match { " AND group_id IN(" . join(', ', (-1, @{$user->visible_groups_inherited})) . ") "; } - $query .= " AND disabledtext = '' " if $exclude_disabled; + $query .= " AND is_enabled = 1 " if $exclude_disabled; $query .= $dbh->sql_limit($limit) if $limit; my $user_ids = $dbh->selectcol_arrayref($query, undef, ($str, $str)); @users = @{Bugzilla::User->new_from_list($user_ids)}; @@ -1781,7 +1804,7 @@ sub get_userlist { "AND group_id IN(" . join(', ', (-1, @{$self->visible_groups_inherited})) . ")"; } - $query .= " WHERE disabledtext = '' "; + $query .= " WHERE is_enabled = 1 "; $query .= $dbh->sql_group_by('userid', 'login_name, realname'); my $sth = $dbh->prepare($query); -- cgit v1.2.3-24-g4f1b