Commit c1a23576 authored by Gaël Berthaud-Müller's avatar Gaël Berthaud-Müller Committed by Alexandre
Browse files

insert result entries in one query

parent 8ce76040
......@@ -487,6 +487,31 @@ sub add_result_entry {
return $nb_inserted;
}
sub add_result_entries {
my ( $self, $hash_id, $entries ) = @_;
my @records;
my $json = JSON::PP->new->allow_blessed->convert_blessed->canonical;
foreach my $m ( @$entries ) {
my $r = [
$hash_id,
$m->level,
$m->module,
$m->testcase,
$m->tag,
$m->timestamp,
$json->encode( $m->args // {} ),
];
push @records, $r;
}
my $query_values = join ", ", ("(?, ?, ?, ?, ?, ?, ?)") x @records;
my $query = "INSERT INTO result_entries (hash_id, level, module, testcase, tag, timestamp, args) VALUES $query_values";
my $sth = $self->dbh->prepare($query);
$sth = $sth->execute(map { @$_ } @records);
}
no Moose::Role;
1;
......@@ -95,19 +95,19 @@ sub run {
my ( $entry ) = @_;
# TODO: Make minimum level configurable
if ( $entry->numeric_level >= $numeric{INFO} ) {
$log->debug("Adding result entry in database: " . $entry->string);
$self->{_db}->add_result_entry( $test_id, {
timestamp => $entry->timestamp,
module => $entry->module,
testcase => $entry->testcase,
tag => $entry->tag,
level => $entry->level,
args => $entry->args // {},
});
# if ( $entry->numeric_level >= $numeric{INFO} ) {
# $log->debug("Adding result entry in database: " . $entry->string);
}
# $self->{_db}->add_result_entry( $test_id, {
# timestamp => $entry->timestamp,
# module => $entry->module,
# testcase => $entry->testcase,
# tag => $entry->tag,
# level => $entry->level,
# args => $entry->args // {},
# });
# }
foreach my $trace ( reverse @{ $entry->trace } ) {
foreach my $module_method ( keys %{ $counter_for_progress_indicator{planned} } ) {
......@@ -190,6 +190,10 @@ sub run {
$progress = $self->{_db}->test_progress( $test_id, 100 );
my @entries = grep { $_->numeric_level >= $numeric{INFO} } @{ Zonemaster::Engine->logger->entries };
$self->{_db}->add_result_entries( $test_id, \@entries);
return;
} ## end sub run
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment