Bug 658929 - User autocomplete is very slow when there are lots of users in the profiles table

r/a=mkanat


git-svn-id: svn://10.0.0.236/trunk@262460 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mkanat%bugzilla.org
2011-07-05 16:16:29 +00:00
parent 11eabdd8c1
commit 5dcfbcc335
10 changed files with 55 additions and 15 deletions

View File

@@ -86,7 +86,7 @@ sub login {
# Make sure the user isn't disabled.
my $user = $login_info->{user};
if ($user->disabledtext) {
if (!$user->is_enabled) {
return $self->_handle_login_result({ failure => AUTH_DISABLED,
user => $user }, $type);
}

View File

@@ -885,6 +885,8 @@ use constant ABSTRACT_SCHEMA => {
mybugslink => {TYPE => 'BOOLEAN', NOTNULL => 1,
DEFAULT => 'TRUE'},
extern_id => {TYPE => 'varchar(64)'},
is_enabled => {TYPE => 'BOOLEAN', NOTNULL => 1,
DEFAULT => 'TRUE'},
],
INDEXES => [
profiles_login_name_idx => {FIELDS => ['login_name'],

View File

@@ -651,6 +651,9 @@ sub update_table_definitions {
_populate_bug_see_also_class();
# 2011-06-15 dkl@mozilla.com - Bug 658929
_migrate_disabledtext_boolean();
################################################################
# New --TABLE-- changes should go *** A B O V E *** this point #
################################################################
@@ -3573,6 +3576,16 @@ sub _populate_bug_see_also_class {
$dbh->bz_commit_transaction();
}
sub _migrate_disabledtext_boolean {
my $dbh = Bugzilla->dbh;
if (!$dbh->bz_column_info('profiles', 'is_enabled')) {
$dbh->bz_add_column("profiles", 'is_enabled',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'TRUE'});
$dbh->do("UPDATE profiles SET is_enabled = 0
WHERE disabledtext != ''");
}
}
1;
__END__

View File

@@ -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);

View File

@@ -218,7 +218,7 @@ sub get {
real_name => $self->type('string', $_->name),
name => $self->type('string', $_->login),
email => $self->type('string', $_->email),
can_login => $self->type('boolean', $_->is_disabled ? 0 : 1),
can_login => $self->type('boolean', $_->is_enabled ? 1 : 0),
email_enabled => $self->type('boolean', $_->email_enabled),
login_denied_text => $self->type('string', $_->disabledtext),
}} @$in_group;
@@ -231,7 +231,7 @@ sub get {
real_name => $self->type('string', $_->name),
name => $self->type('string', $_->login),
email => $self->type('string', $_->email),
can_login => $self->type('boolean', $_->is_disabled ? 0 : 1),
can_login => $self->type('boolean', $_->is_enabled ? 1 : 0),
}} @$in_group;
}