]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1348380 - Add param and user setting to control elasticsearch behavior
authorDylan William Hardison <dylan@hardison.net>
Wed, 19 Apr 2017 20:52:00 +0000 (16:52 -0400)
committerDylan William Hardison <dylan@hardison.net>
Wed, 24 May 2017 18:24:54 +0000 (14:24 -0400)
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/Config/Elastic.pm
Bugzilla/Elastic.pm
Bugzilla/Install.pm
buglist.cgi
template/en/default/admin/params/elastic.html.tmpl
template/en/default/global/setting-descs.none.tmpl

index 2b2513f1b0a7f6a029eac38c93b0fcbc5bb46c76..690f5fac5acbd4989c0cbe50c35691f0bb1f2e66 100644 (file)
@@ -16,18 +16,23 @@ use Bugzilla::Config::Common;
 our $sortkey = 1550;
 
 sub get_param_list {
-  return (
-    {
-        name    => 'elasticsearch_nodes',
-        type    => 't',
-        default => 'localhost:9200',
-    },
-    {
-        name    => 'elasticsearch_index',
-        type    => 't',
-        default => 'bugzilla',
-    },
-  );
+    return (
+        {
+            name    => 'elasticsearch',
+            type    => 'b',
+            default => 0,
+        },
+        {
+            name    => 'elasticsearch_nodes',
+            type    => 't',
+            default => 'localhost:9200',
+        },
+        {
+            name    => 'elasticsearch_index',
+            type    => 't',
+            default => 'bugzilla',
+        },
+    );
 }
 
 1;
index 6384269fde7ee164d9b0bb434410f9e314fd5c1a..fa032d2a6dc1540d99c2d99bb74aa2f92940d801 100644 (file)
@@ -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;
index edadbfecb518a014353d697a7cf66be01d061d72..982f4a4fbc20d583c62c5074b3de7b19ce7db83a 100644 (file)
@@ -175,6 +175,12 @@ sub SETTINGS {
         default => 'off',
         category => 'API'
     },
+    {
+        name     => 'use_elasticsearch',
+        options  => ['on', 'off'],
+        default  => 'off',
+        category => 'Searching'
+    },
     ];
 };
 
index fa6bb060fbeb9369957f62259c44beda1fc99260..d2c6545b7917032b99fd38c04323d94a4318b824 100755 (executable)
@@ -692,11 +692,18 @@ my $fallback_search = Bugzilla::Search->new(fields => [@selectcolumns],
                                             order  => [@order_columns],
                                             sharer => $sharer_id);
 
+# Not-logged-in users get elasticsearch if possible
+my $elastic_default = !$user->id || $user->setting('use_elasticsearch') eq 'on';
+
 my $search;
-my $elastic = $cgi->param('elastic') // 1;
+my $elastic = $cgi->param('elastic') // $elastic_default;
 if (defined $cgi->param('elastic')) {
-    $vars->{was_elastic} = 1;
+    $vars->{was_elastic} = $elastic;
 }
+
+# If turned off in the admin section, it is always off.
+$elastic = 0 unless Bugzilla->params->{elasticsearch};
+
 if ($elastic) {
     local $SIG{__DIE__} = undef;
     local $SIG{__WARN__} = undef;
index 47ec088b54d1828ad1c8896bf90eefb17b7ad457..dc5459920d0696cac11219eeacb15b2b21c252c1 100644 (file)
@@ -11,8 +11,8 @@
 %]
 
 [% param_descs = {
+    elasticsearch => "Enable or disable elasticsearch feature."
     elasticsearch_nodes =>
-      "If this option is set, $terms.Bugzilla will integrate with Elasticsearch. " _
       "Specify one of more server, separated by spaces, using hostname[:port] " _
       "notation (for example: localhost).",
 
index 368987da65693f80ef61e57ff8e819255ee7581a..ba001ab6d193d102df3441384107a193768ffd8f 100644 (file)
@@ -56,6 +56,7 @@
    "possible_duplicates"              => "Display possible duplicates when reporting a new $terms.bug",
    "requestee_cc"                     => "Automatically add me to the CC list of $terms.bugs I am requested to review",
    "api_key_only"                     => "Require API key authentication for API requests",
+   "use_elasticsearch"                => "Use elasticsearch for $terms.bug searches when possible",
                    }
 %]