From 54ed8cf5c8a97f9aeccbac30870acebb0059a964 Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Thu, 13 Sep 2018 21:23:30 -0400 Subject: no bug - cleanup a few nits in the SecurityRiskReport (#746) - sorted imports, with Moo and MooX::StrictConstructor at the top because they change the behavior of the code. - removed 'scalar' when comparing an array to an integer as it isn't required. - adjusted multi-line first { } to single line since it still fits and perltidy makes it look ugly. - store each 'result' hash in a $result variable, again to make perltidy format better. - change use of 'unshift ARRAY' to 'push ARRAY' and reverse(). The later performs fewer mallocs (push is much more effficient than unshift). Please check if this logic is right. --- Bugzilla/Report/SecurityRisk.pm | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Bugzilla/Report/SecurityRisk.pm b/Bugzilla/Report/SecurityRisk.pm index 1b62d476c..5eb98fd7f 100644 --- a/Bugzilla/Report/SecurityRisk.pm +++ b/Bugzilla/Report/SecurityRisk.pm @@ -8,19 +8,18 @@ package Bugzilla::Report::SecurityRisk; use 5.10.1; +use Moo; +use MooX::StrictConstructor; -use Bugzilla; use Bugzilla::Error; use Bugzilla::Status qw(is_open_state); use Bugzilla::Util qw(datetime_from); - +use Bugzilla; use DateTime; use List::Util qw(any first sum); -use Moo; -use MooX::StrictConstructor; use POSIX qw(ceil); -use Types::Standard qw(Num Int Bool Str HashRef ArrayRef CodeRef Map Dict Enum); use Type::Utils; +use Types::Standard qw(Num Int Bool Str HashRef ArrayRef CodeRef Map Dict Enum); my $DateTime = class_type { class => 'DateTime' }; @@ -202,7 +201,7 @@ sub _build_results { # We rewind events while there are still events existing which occured after the start # of the report week. The bugs will reflect a snapshot of how they were at the start of the week. # $self->events is ordered reverse chronologically, so the end of the array is the earliest event. - while ( $e < scalar @{ $self->events } + while ( $e < @{ $self->events } && ( @{ $self->events }[$e] )->{bug_when} > $report_date ) { my $event = @{ $self->events }[$e]; @@ -222,10 +221,7 @@ sub _build_results { } if ( $event->{removed} ) { # If a target sec keyword was removed, add the first one back. - my $removed_sec = first { - $event->{removed} =~ /\b\Q$_\E\b/ - } - @{ $self->sec_keywords }; + my $removed_sec = first { $event->{removed} =~ /\b\Q$_\E\b/ } @{ $self->sec_keywords }; $bug->{sec_level} = $removed_sec if ($removed_sec); } } @@ -243,15 +239,15 @@ sub _build_results { # Report! my $date_snapshot = $report_date->clone(); my @bugs_snapshot = values %$bugs; - unshift @results, - { + my $result = { date => $date_snapshot, bugs_by_product => $self->_bugs_by_product( $date_snapshot, @bugs_snapshot ), bugs_by_sec_keyword => $self->_bugs_by_sec_keyword( $date_snapshot, @bugs_snapshot ), - }; + }; + push @results, $result; } - return \@results; + return [reverse @results]; } sub _bugs_by_product { -- cgit v1.2.3-24-g4f1b