]> git.donarmstrong.com Git - debbugs.git/blobdiff - Debbugs/Bugs.pm
fix db_search options to use [] and {} when appropriate
[debbugs.git] / Debbugs / Bugs.pm
index 8162bd301b846d9f7cc5eb2ae7f26307bfecc7e7..32bb390ddf47109f8b1c1de6d7ee52e009fa66b1 100644 (file)
@@ -37,6 +37,7 @@ incomplete) to slowest (and most complete).]
 
 use warnings;
 use strict;
+use feature 'state';
 use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT);
 use Exporter qw(import);
 
@@ -58,7 +59,7 @@ use Debbugs::Packages qw(getsrcpkgs getpkgsrc);
 use Debbugs::Common qw(getparsedaddrs package_maintainer getmaintainers make_list hash_slice);
 use Fcntl qw(O_RDONLY);
 use MLDBM qw(DB_File Storable);
-use List::Util qw(first);
+use List::AllUtils qw(first);
 use Carp;
 
 =head2 get_bugs
@@ -152,7 +153,7 @@ bug should not.
 
 =cut
 
-my $_non_search_key_regex = qr/^(bugs|archive|usertags|schema)$/;
+state $_non_search_key_regex = qr/^(bugs|archive|usertags|schema)$/;
 
 my %_get_bugs_common_options =
     (package   => {type => SCALAR|ARRAYREF,
@@ -206,7 +207,7 @@ my %_get_bugs_common_options =
     );
 
 
-my $_get_bugs_options = {%_get_bugs_common_options};
+state $_get_bugs_options = {%_get_bugs_common_options};
 sub get_bugs{
      my %param = validate_with(params => \@_,
                               spec   => $_get_bugs_options,
@@ -399,7 +400,7 @@ searches.
 =cut
 
 
-my $_get_bugs_by_idx_options =
+state $_get_bugs_by_idx_options =
    {hash_slice(%_get_bugs_common_options,
                (qw(package submitter severity tag archive),
                 qw(owner src maint bugs correspondent),
@@ -487,7 +488,7 @@ searches.
 
 =cut
 
-my $_get_bugs_by_db_options =
+state $_get_bugs_by_db_options =
    {hash_slice(%_get_bugs_common_options,
                (qw(package submitter severity tag archive),
                 qw(owner src maint bugs correspondent),
@@ -502,52 +503,45 @@ sub get_bugs_by_db{
                               );
      my %bugs = ();
 
-     # If we're given an empty maint (unmaintained packages), we can't
-     # handle it, so bail out here
-     for my $maint (make_list(exists $param{maint}?$param{maint}:[])) {
-         if (defined $maint and $maint eq '') {
-              die "Can't handle empty maint (unmaintained packages) in get_bugs_by_db";
-         }
-     }
-
-     # We handle src packages, maint and maintenc by mapping to the
-     # appropriate binary packages, then removing all packages which
-     # don't match all queries
-     my @packages = __handle_pkg_src_and_maint(map {exists $param{$_}?($_,$param{$_}):()}
-                                              qw(package src maint)
-                                             );
-     if (exists $param{package} or
-        exists $param{src} or
-        exists $param{maint}) {
-         delete @param{qw(maint src)};
-         $param{package} = [@packages];
-     }
      my $keys = grep {$_ !~ $_non_search_key_regex} keys(%param);
      die "Need at least 1 key to search by" unless $keys;
      my $rs = $param{schema}->resultset('Bug');
+     if (exists $param{package}) {
+        $rs = $rs->search({-or => {map 'bin_package.'}})
+     }
      if (exists $param{severity}) {
-         $rs = $rs->search([map {('severity.severity' => $_)} make_list($param{severity})],
+         $rs = $rs->search({'severity.severity' =>
+                           [make_list($param{severity})],
+                          },
                           {join => 'severity'},
                           );
      }
      for my $key (qw(owner submitter done)) {
          if (exists $param{$key}) {
-             $rs = $rs->search([map {("${key}.addr" => $_)} make_list($param{$key})],
+             $rs = $rs->search({"${key}.addr" =>
+                               [make_list($param{$key})],
+                              },
                               {join => $key},
                               );
          }
      }
      if (exists $param{correspondent}) {
-         $rs = $rs->search([map {('message_correspondents.addr' => $_)} make_list($param{correspondent})],
+         $rs = $rs->search({'message_correspondents.addr' =>
+                           [make_list($param{correspondent})],
+                          },
                           {join => {correspondent =>
                                    {bug_messages =>
                                    {message => 'message_correspondents'}}}},
                           );
      }
      if (exists $param{affects}) {
-         $rs = $rs->search([map {('bin_pkg.pkg' => $_)} make_list($param{affects}),
-                            map {('src_pkg.pkg' => $_)} make_list($param{affects}),
-                           ],
+        my @aff_list = make_list($param{affects});
+         $rs = $rs->search({-or => {'bin_pkg.pkg' =>
+                                   [@aff_list],
+                                   'src_pkg.pkg' =>
+                                   [@aff_list],
+                                  },
+                          },
                           {join => [{bug_affects_binpackages => 'bin_pkg'},
                                    {bug_affects_srcpackages => 'src_pkg'},
                                    ],
@@ -555,34 +549,66 @@ sub get_bugs_by_db{
                           );
      }
      if (exists $param{package}) {
-         $rs = $rs->search([map {('bin_pkg.pkg' => $_)} make_list($param{package})],
+         $rs = $rs->search({'bin_pkg.pkg' =>
+                           [make_list($param{package})],
+                          },
                           {join => {bug_binpackages => 'bin_pkg'}});
      }
+     if (exists $param{maintainer}) {
+        my @maint_list =
+            map {$_ eq '' ? undef : $_}
+            make_list($param{maintainer});
+        $rs = $rs->search({-or => {correspondent => [@maint_list],
+                                   correspondent2 => [@maint_list],
+                                  },
+                          },
+                         {join => {bug_affects_binpackage =>
+                                  {bin_pkg =>
+                                  {bin_ver =>
+                                  {src_ver =>
+                                  {maintainer => 'correspondent'}
+                                  }}},
+                                  {bug_affects_srcpackage =>
+                                  {src_pkg =>
+                                  {src_ver =>
+                                  {maintainer => 'correspondent'}
+                                  }}}}
+                         }
+                         );
+     }
      if (exists $param{src}) {
-         $rs = $rs->search([map {('src_pkg.pkg' => $_)} make_list($param{src})],
+         $rs = $rs->search({-or => {map {('src_pkg.pkg' => $_)}
+                                   make_list($param{src})},
+                          },
                           {join => {bug_srcpackages => 'src_pkg'}});
      }
      # tags are very odd, because we must handle usertags.
      if (exists $param{tag}) {
          # bugs from usertags which matter
          my %bugs_matching_usertags;
-         for my $bug (make_list(grep {defined $_ } @{$param{usertags}}{make_list($param{tag})})) {
+         for my $bug (make_list(grep {defined $_ }
+                               @{$param{usertags}}{make_list($param{tag})})) {
              $bugs_matching_usertags{$bug} = 1;
          }
          # we want all bugs which either match the tag name given in
          # param, or have a usertag set which matches one of the tag
          # names given in param.
-         $rs = $rs->search([map {('tag.tag' => $_)} make_list($param{tag}),
-                            map {('me.id' => $_)} keys %bugs_matching_usertags
-                           ],
+         $rs = $rs->search({-or => {map {('tag.tag' => $_)}
+                                   make_list($param{tag}),
+                                   map {('me.id' => $_)}
+                                   keys %bugs_matching_usertags
+                                  },
+                          },
                           {join => {bug_tags => 'tag'}});
      }
      if (exists $param{bugs}) {
-         $rs = $rs->search([map {('me.id' => $_)} make_list($param{bugs})]);
+         $rs = $rs->search({-or => {map {('me.id' => $_)}
+                                   make_list($param{bugs})}
+                          });
      }
      # handle archive
      if (defined $param{archive} and $param{archive} ne 'both') {
-         $rs = $rs->search({'me.archived' => $param{archive}})
+         $rs = $rs->search({'me.archived' => $param{archive}});
      }
      return $rs->get_column('id')->all();
 }
@@ -595,7 +621,7 @@ searches. [Or at least, that's the idea.]
 
 =cut
 
-my $_get_bugs_flatfile_options =
+state $_get_bugs_flatfile_options =
    {hash_slice(%_get_bugs_common_options,
                map {$_ eq 'dist'?():($_)} keys %_get_bugs_common_options
               )
@@ -804,7 +830,7 @@ sub __handle_pkg_src_and_maint{
      return grep {$packages{$_} >= $package_keys} keys %packages;
 }
 
-my %field_match = (
+state %field_match = (
     'subject' => \&__contains_field_match,
     'tags' => sub {
         my ($field, $values, $status) = @_;