]> git.donarmstrong.com Git - debbugs.git/blobdiff - Debbugs/Bugs.pm
allow specifying the dist in source_to_binary (for DB actions)
[debbugs.git] / Debbugs / Bugs.pm
index 095ed763b98dfdc45c0e3433a8b357f5ce54dc1c..60217124dd067cb8b547731e6f14aeb234c0edd0 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);
 
@@ -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,42 +503,52 @@ sub get_bugs_by_db{
                               );
      my %bugs = ();
 
+     my $s = $param{schema};
      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.'}})
-     }
+     my $rs = $s->resultset('Bug');
      if (exists $param{severity}) {
-         $rs = $rs->search({-or => {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({-or => {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({-or => {map {('message_correspondents.addr' => $_)}
-                                   make_list($param{correspondent})},
+        my $message_rs =
+            $s->resultset('Message')->
+            search({'correspondent.addr' =>
+                    [make_list($param{correspondent})],
+                   },
+                  {join => {message_correspondents => 'correspondent'},
+                   columns => ['id'],
+                   group_by => ['me.id'],
+                  },
+                  );
+         $rs = $rs->search({'bug_messages.message' =>
+                          {-in => $message_rs->get_column('id')->as_query()},
                           },
-                          {join => {correspondent =>
-                                   {bug_messages =>
-                                   {message => 'message_correspondents'}}}},
+                          {join => 'bug_messages',
+                         },
                           );
      }
      if (exists $param{affects}) {
-         $rs = $rs->search({-or => {map {('bin_pkg.pkg' => $_,
-                                         '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],
+                                   'me.unknown_affects' =>
+                                   [@aff_list]
                                   },
                           },
                           {join => [{bug_affects_binpackages => 'bin_pkg'},
@@ -547,37 +558,80 @@ sub get_bugs_by_db{
                           );
      }
      if (exists $param{package}) {
-         $rs = $rs->search({-or => {map {('bin_pkg.pkg' => $_)}
-                                   make_list($param{package})},
+         $rs = $rs->search({-or => {'bin_pkg.pkg' =>
+                                   [make_list($param{package})],
+                                   'me.unknown.package' =>
+                                   [make_list($param{package})]},
                           },
                           {join => {bug_binpackages => 'bin_pkg'}});
      }
-     if (exists $param{maintainer}) {
-        $rs = $rs->search({-or => {map {(correspondent => $_ eq '' ? undef : $_,
-                                         correspondent2 => $_ eq '' ? undef : $_,
-                                        )}
-                                   make_list($param{maintainer})
-                                  }
+     if (exists $param{maint}) {
+        my @maint_list =
+            map {$_ eq '' ? undef : $_}
+            make_list($param{maint});
+        my $bin_pkgs_rs =
+            $s->resultset('BinPkg')->
+            search({'correspondent.addr' => [@maint_list]},
+                  {join => {bin_vers =>
+                           {src_ver =>
+                           {maintainer => 'correspondent'}}},
+                   columns => ['id'],
+                   group_by => ['me.id'],
+                  },
+                  );
+        my $src_pkgs_rs =
+            $s->resultset('SrcPkg')->
+            search({'correspondent.addr' => [@maint_list]},
+                  {join => {src_vers =>
+                           {maintainer => 'correspondent'}},
+                   columns => ['id'],
+                   group_by => ['me.id'],
+                  },
+                  );
+        $rs = $rs->search({-or => {'bug_binpackages.bin_pkg' =>
+                                  { -in => $bin_pkgs_rs->get_column('id')->as_query},
+                                   'bug_srcpackages.src_pkg' => 
+                                  { -in => $bin_pkgs_rs->get_column('id')->as_query},
+                                  },
                           },
-                         {join => {bug_affects_binpackage =>
-                                  {bin_pkg =>
-                                  {bin_ver =>
-                                  {src_ver =>
-                                  {maintainer => 'correspondent'}
-                                  }}},
-                                  {bug_affects_srcpackage =>
-                                  {src_pkg =>
-                                  {src_ver =>
-                                  {maintainer => 'correspondent'}
-                                  }}}}
-                         }
+                         {join => ['bug_binpackages',
+                                   'bug_srcpackages',
+                                  ]}
                          );
      }
      if (exists $param{src}) {
-         $rs = $rs->search({-or => {map {('src_pkg.pkg' => $_)}
-                                   make_list($param{src})},
+        # identify all of the srcpackages and binpackages that match first
+        my $src_pkgs_rs =
+        $s->resultset('SrcPkg')->
+            search({-or => [map {('me.pkg' => $_,
+                                 )}
+                            make_list($param{src})],
+                    columns => ['id'],
+                    group_by => ['me.id'],
+                   },
+                  );
+        my $bin_pkgs_rs =
+        $s->resultset('BinPkg')->
+            search({-or => [map {('src_pkg.pkg' => $_,
+                                 )}
+                            make_list($param{src})],
+                    },
+                  {join => {bin_vers => {src_ver => 'src_pkg'}},
+                   columns => ['id'],
+                   group_by => ['me.id'],
+                  });
+         $rs = $rs->search({-or => {'bug_binpackages.bin_pkg' =>
+                                  { -in => $bin_pkgs_rs->get_column('id')->as_query},
+                                   'bug_srcpackages.src_pkg' => 
+                                  { -in => $bin_pkgs_rs->get_column('id')->as_query},
+                                   'me.unknown_package' =>
+                                   [make_list($param{src})],
+                                  },
                           },
-                          {join => {bug_srcpackages => 'src_pkg'}});
+                         {join => ['bug_binpackages',
+                                   'bug_srcpackages',
+                                  ]}
+                         );
      }
      # tags are very odd, because we must handle usertags.
      if (exists $param{tag}) {
@@ -618,7 +672,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
               )
@@ -827,7 +881,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) = @_; 
@@ -843,14 +897,14 @@ my %field_match = (
     'originator' => \&__contains_field_match,
     'forwarded' => \&__contains_field_match,
     'owner' => \&__contains_field_match,
-);
+};
 
 sub __bug_matches {
     my ($hash, $status) = @_;
     foreach my $key( keys( %$hash ) ) {
         my $value = $hash->{$key};
-       next unless exists $field_match{$key};
-       my $sub = $field_match{$key};
+       next unless exists $field_match->{$key};
+       my $sub = $field_match->{$key};
        if (not defined $sub) {
            die "No defined subroutine for key: $key";
        }