Skip to content

Instantly share code, notes, and snippets.

@cfedde
Created March 27, 2014 15:49
Show Gist options
  • Save cfedde/9810663 to your computer and use it in GitHub Desktop.
Save cfedde/9810663 to your computer and use it in GitHub Desktop.
The while loop is very slow. What am I doing wrong?
#!/usr/bin/env perl
use Modern::Perl;
use BCV::DB;
use Search::Elasticsearch;
use JSON;
my $DB = BCV::DB->new($ENV{BOOTLOGDB}//'BCVcore');
my $e = Search::Elasticsearch->new( nodes => 'bcvdb02:9200' );
my $index = 'crfbootlogdata';
my $idseq = 1;
my $query = q| select * from phone_boot_log_records |;
my $sth = $DB->prepare($query);
$sth->execute;
if ($e->indices->exists(index => $index)) {
$e->indices->delete( index => $index );
$e->indices->create( index => $index );
}
while (my $r = $sth->fetchrow_hashref) {
$e->index(
index => $index,
type => 'broadsoft-bootlog',
id => $idseq++,
body => $r,
);
say encode_json($r);
}
$DB->disconnect;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment