Created
March 27, 2014 15:49
-
-
Save cfedde/9810663 to your computer and use it in GitHub Desktop.
The while loop is very slow. What am I doing wrong?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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