From: Don Armstrong Date: Thu, 19 Sep 2013 15:50:18 +0000 (-0700) Subject: create and use get_status_and_filter to only retreive status once X-Git-Url: https://git.donarmstrong.com/?p=debbugs.git;a=commitdiff_plain;h=ec32f7d1acf9f5761914c46e06b8ee80843973c0 create and use get_status_and_filter to only retreive status once --- diff --git a/Debbugs/CGI/Pkgreport.pm b/Debbugs/CGI/Pkgreport.pm index 8c217d7..be34555 100644 --- a/Debbugs/CGI/Pkgreport.pm +++ b/Debbugs/CGI/Pkgreport.pm @@ -54,6 +54,7 @@ BEGIN{ ], misc => [qw(generate_package_info), qw(determine_ordering), + qw(get_status_and_filter), ], ); @EXPORT_OK = (qw()); @@ -259,49 +260,107 @@ sub short_bug_status_html { ); } +our %_get_status_and_filter_params = + (bugs => {type => ARRAYREF, + }, + bugusertags => {type => HASHREF, + default => {}, + }, + repeatmerged => {type => BOOLEAN, + default => 1, + }, + include => {type => ARRAYREF, + default => [], + }, + exclude => {type => ARRAYREF, + default => [], + }, + dist => {type => SCALAR, + optional => 1, + }, + version => {type => SCALAR, + optional => 1, + }, + ); + + +sub get_status_and_filter { + my %param = validate_with(params => \@_, + spec => {%_get_status_and_filter_params}, + ); + my %seenmerged; + my %statuses; + + my %include; + my %exclude; + for my $include (make_list($param{include})) { + next unless defined $include; + my ($key,$value) = split /\s*:\s*/,$include,2; + unless (defined $value) { + $key = 'tags'; + $value = $include; + } + push @{$include{$key}}, split /\s*,\s*/, $value; + } + for my $exclude (make_list($param{exclude})) { + next unless defined $exclude; + my ($key,$value) = split /\s*:\s*/,$exclude,2; + unless (defined $value) { + $key = 'tags'; + $value = $exclude; + } + push @{$exclude{$key}}, split /\s*,\s*/, $value; + } + + foreach my $bug (@{$param{bugs}}) { + my $status = get_bug_status(bug=>$bug, + (exists $param{dist}?(dist => $param{dist}):()), + bugusertags => $param{bugusertags}, + (exists $param{version}?(version => $param{version}):()), + (exists $param{arch}?(arch => $param{arch}):(arch => $config{default_architectures})), + ); + next unless keys $status; + next if bug_filter(bug => $bug, + status => $status, + repeat_merged => $param{repeatmerged}, + seen_merged => \%seenmerged, + (keys %include ? (include => \%include):()), + (keys %exclude ? (exclude => \%exclude):()), + ); + $statuses{$bug} = $status; + } + return \%statuses; + +} + sub pkg_htmlizebugs { - my %param = validate_with(params => \@_, - spec => {bugs => {type => ARRAYREF, - }, - names => {type => ARRAYREF, - }, - title => {type => ARRAYREF, - }, - prior => {type => ARRAYREF, - }, - order => {type => ARRAYREF, - }, - ordering => {type => SCALAR, - }, - bugusertags => {type => HASHREF, - default => {}, - }, - bug_rev => {type => BOOLEAN, - default => 0, - }, - bug_order => {type => SCALAR, - }, - repeatmerged => {type => BOOLEAN, - default => 1, - }, - include => {type => ARRAYREF, - default => [], - }, - exclude => {type => ARRAYREF, - default => [], - }, - this => {type => SCALAR, - default => '', - }, - options => {type => HASHREF, - default => {}, - }, - dist => {type => SCALAR, - optional => 1, - }, - } - ); + my %param = validate_with(params => \@_, + spec => {%_get_status_and_filter_params, + bugs => {type => ARRAYREF, + }, + bug_status => {type => HASHREF, + }, + names => {type => ARRAYREF, + }, + title => {type => ARRAYREF, + }, + prior => {type => ARRAYREF, + }, + order => {type => ARRAYREF, + }, + ordering => {type => SCALAR, + }, + bug_rev => {type => BOOLEAN, + default => 0, + }, + bug_order => {type => SCALAR, + }, + options => {type => HASHREF, + default => {}, + }, + } + ); my @bugs = @{$param{bugs}}; my @status = (); @@ -328,49 +387,22 @@ sub pkg_htmlizebugs { my %section = (); # Make the include/exclude map - my %include; - my %exclude; - for my $include (make_list($param{include})) { - next unless defined $include; - my ($key,$value) = split /\s*:\s*/,$include,2; - unless (defined $value) { - $key = 'tags'; - $value = $include; - } - push @{$include{$key}}, split /\s*,\s*/, $value; - } - for my $exclude (make_list($param{exclude})) { - next unless defined $exclude; - my ($key,$value) = split /\s*:\s*/,$exclude,2; - unless (defined $value) { - $key = 'tags'; - $value = $exclude; - } - push @{$exclude{$key}}, split /\s*,\s*/, $value; + if (not exists $param{bug_status}) { + $param{bug_status} = + get_status_and_filter(map{exists $param{$_}?($_,$param{$_}):()} + keys %_get_status_and_filter_params); + @bugs = sort keys %{$param{bug_status}}; } - foreach my $bug (@bugs) { - my %status = %{get_bug_status(bug=>$bug, - (exists $param{dist}?(dist => $param{dist}):()), - bugusertags => $param{bugusertags}, - (exists $param{version}?(version => $param{version}):()), - (exists $param{arch}?(arch => $param{arch}):(arch => $config{default_architectures})), - )}; - next unless %status; - next if bug_filter(bug => $bug, - status => \%status, - repeat_merged => $param{repeatmerged}, - seen_merged => \%seenmerged, - (keys %include ? (include => \%include):()), - (keys %exclude ? (exclude => \%exclude):()), - ); - - my $html = "
  • "; ##%d: %s\n
    ", - #bug_url($bug), $bug, html_escape($status{subject}); - $html .= short_bug_status_html(status => \%status, - options => $param{options}, - ) . "\n"; - push @status, [ $bug, \%status, $html ]; + if (not exists $param{bug_status}{$bug}) { + use Data::Printer; + p $param{bug_status}; + die "No status for $bug"; + } + my $html = short_bug_status_html(status => $param{bug_status}{$bug}, + options => $param{options}, + ) . "\n"; + push @status, [ $bug, $param{bug_status}{$bug}, $html ]; } if ($param{bug_order} eq 'age') { # MWHAHAHAHA @@ -386,13 +418,13 @@ sub pkg_htmlizebugs { $count{"g_${i}_${v}"}++; $key .= "_$v"; } - $section{$key} .= $entry->[2]; + push @{$section{$key}}, $entry->[2]; $count{"_$key"}++; } my $result = ""; if ($param{ordering} eq "raw") { - $result .= "\n"; + $result .= "\n"; } else { $header .= "
    \n
      \n"; @@ -407,7 +439,7 @@ sub pkg_htmlizebugs { } } for my $order (@keys_in_order) { - next unless defined $section{$order}; + next unless defined $section{$order} and @{$section{$order}}; my @ttl = split /_/, $order; shift @ttl; my $title = $param{title}[0]->[$ttl[0]] . " bugs"; @@ -432,7 +464,7 @@ sub pkg_htmlizebugs { } $result .= "
      \n
        \n"; $result .= "\n\n\n\n"; - $result .= $section{$order}; + $result .= join("",@{$section{$order}||[]}); $result .= "\n\n\n\n"; $result .= "
      \n
      \n"; } diff --git a/cgi/pkgreport.cgi b/cgi/pkgreport.cgi index eb7a61a..d83f93c 100755 --- a/cgi/pkgreport.cgi +++ b/cgi/pkgreport.cgi @@ -217,7 +217,7 @@ our %cats = ( } ], "classification" => [ { "nam" => "Classification", - "pri" => [qw(pending=pending+tag=wontfix + "pri" => [qw(pending=pending+tag=wontfix pending=pending+tag=moreinfo pending=pending+tag=patch pending=pending+tag=confirmed @@ -393,7 +393,14 @@ if (not exists $param{affects} and not exists $param{noaffects} and } # filter out included or excluded bugs - +my $bug_status = + get_status_and_filter(bugs => \@bugs, + bugusertags => \%bugusertags, + repeatmerged => $param{repeatmerged}, + include => $include, + exclude => $exclude, + (exists $param{dist})?(dist => $param{dist}):(),); +@bugs = keys %{$bug_status}; if (defined $param{version}) { $title .= " at version $param{version}"; @@ -404,7 +411,10 @@ elsif (defined $param{dist}) { $title = html_escape($title); -my @names; my @prior; my @order; +my @names; +# @prior contains the priority of the categories; numbers closer to +# zero are shown nearer the top +my @prior; my @order; determine_ordering(cats => \%cats, param => \%param, ordering => \$ordering, @@ -420,21 +430,18 @@ my %bugs; @bugs = keys %bugs; my $result = pkg_htmlizebugs(bugs => \@bugs, - names => \@names, - title => \@title, - order => \@order, - prior => \@prior, - ordering => $ordering, - bugusertags => \%bugusertags, - bug_rev => $bug_rev, - bug_order => $bug_order, - repeatmerged => $param{repeatmerged}, - include => $include, - exclude => $exclude, - this => $this, - options => \%param, - (exists $param{dist})?(dist => $param{dist}):(), - ); + bug_status => $bug_status, + names => \@names, + title => \@title, + order => \@order, + prior => \@prior, + ordering => $ordering, + bugusertags => \%bugusertags, + bug_rev => $bug_rev, + bug_order => $bug_order, + options => \%param, + (exists $param{dist})?(dist => $param{dist}):(), + ); print "Content-Type: text/html; charset=utf-8\n\n"; @@ -451,8 +458,8 @@ print "

      " . "$gProject$Archived $gBug report logs: $title" . my $showresult = 1; -my $pkg = $param{package} if defined $param{package}; -my $src = $param{src} if defined $param{src}; +my ($pkg) = make_list($param{package}) if defined $param{package}; +my ($src) = make_list($param{src}) if defined $param{src}; my $pseudodesc = getpseudodesc(); if (defined $pseudodesc and defined $pkg and exists $pseudodesc->{$pkg}) {