From ffe838a923696f81e8d8e1f24c5dc7a568cbc6ac Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Wed, 19 Apr 2017 16:52:00 -0400 Subject: Bug 1348380 - Add param and user setting to control elasticsearch behavior 1) add an 'elasticsearch' param (configured via admin.cgi) that turns off all code that would attempt to connect to elasticsearch. 2) add a user preference that controls using elasticsearch for searches, which defaults to off for logged-in users. Anonymous users will default to using elasticsearch for the greater good. Note that elasticsearch, if available, will still power user-autocompletion (unless turned off as by the above parameter). --- Bugzilla/Elastic.pm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'Bugzilla/Elastic.pm') diff --git a/Bugzilla/Elastic.pm b/Bugzilla/Elastic.pm index 6384269fd..fa032d2a6 100644 --- a/Bugzilla/Elastic.pm +++ b/Bugzilla/Elastic.pm @@ -16,6 +16,12 @@ with 'Bugzilla::Elastic::Role::HasIndexName'; sub suggest_users { my ($self, $text) = @_; + + unless (Bugzilla->params->{elasticsearch}) { + # optimization: faster than a regular method call. + goto &_suggest_users_fallback; + } + my $field = 'suggest_user'; if ($text =~ /^:(.+)$/) { $text = $1; @@ -38,10 +44,15 @@ sub suggest_users { } else { warn "suggest_users error: $@"; - my $users = Bugzilla::User::match($text, 25, 0); - return [ map { { real_name => $_->name, name => $_->login } } @$users]; + # optimization: faster than a regular method call. + goto &_suggest_users_fallback; } } +sub _suggest_users_fallback { + my ($self, $text) = @_; + my $users = Bugzilla::User::match($text, 25, 0); + return [ map { { real_name => $_->name, name => $_->login } } @$users]; +} 1; -- cgit v1.2.3-24-g4f1b