diff options
author | Dylan William Hardison <dylan@hardison.net> | 2016-11-20 00:12:39 +0100 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2017-01-04 23:30:47 +0100 |
commit | 419f3ae9fd57fc4e03146a830f7ed780ace83937 (patch) | |
tree | f368b61dab21eb036e4b91e1ec947a4b9eeabae9 /scripts | |
parent | 840bbad83e4672fc84083437e384f0d332020f53 (diff) | |
download | bugzilla-419f3ae9fd57fc4e03146a830f7ed780ace83937.tar.gz bugzilla-419f3ae9fd57fc4e03146a830f7ed780ace83937.tar.xz |
Bug 1307478 - Elasticsearch Indexer / Bulk Indexer
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/bulk_index.pl | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/scripts/bulk_index.pl b/scripts/bulk_index.pl new file mode 100644 index 000000000..d501ded39 --- /dev/null +++ b/scripts/bulk_index.pl @@ -0,0 +1,70 @@ +#!/usr/bin/perl +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. +use strict; +use warnings; +use 5.10.1; +use Bugzilla; +BEGIN { Bugzilla->extensions } + +use Bugzilla::Elastic::Indexer; +use IO::Async::Timer::Periodic; +use IO::Async::Loop; +use Time::HiRes qw(time); + +use Getopt::Long qw(:config gnu_getopt); + +my ($debug_sql, $progress_bar, $once); +my $verbose = 0; + +GetOptions( + 'verbose|v+' => \$verbose, + 'debug-sql' => \$debug_sql, + 'progress-bar' => \$progress_bar, + 'once|n' => \$once, +); + +if ($progress_bar) { + $progress_bar = eval { require Term::ProgressBar; 1}; +} + +my $indexer = Bugzilla::Elastic::Indexer->new( + $debug_sql ? ( debug_sql => 1 ) : (), + $progress_bar ? ( progress_bar => 'Term::ProgressBar' ) : (), +); + +$indexer->create_index; + +my $loop = IO::Async::Loop->new; +my $timer = IO::Async::Timer::Periodic->new( + first_interval => 0, + interval => 15, + reschedule => 'skip', + + on_tick => sub { + my $start_users = time; + say "indexing users" if $verbose; + $indexer->bulk_load('Bugzilla::User'); + print " ", time - $start_users, " seconds\n" if $verbose > 1; + + say "indexing bugs" if $verbose; + my $start_bugs = time; + $indexer->bulk_load('Bugzilla::Bug'); + print " ", time - $start_bugs, " seconds\n" if $verbose > 1; + + say "indexing comments" if $verbose; + my $start_comments = time; + $indexer->bulk_load('Bugzilla::Comment'); + print " ", time - $start_comments, " seconds\n" if $verbose > 1; + + $loop->stop if $once; + }, +); + +$timer->start(); +$loop->add($timer); +$loop->run; |