]> git.donarmstrong.com Git - debbugs.git/blobdiff - Debbugs/Bugs.pm
OR is the default for multiple values; remove useless or
[debbugs.git] / Debbugs / Bugs.pm
index 3209e5250091341fb532ec2a98947570e0012f41..127e4727248b11457a021c987cb74b83377e6a2e 100644 (file)
@@ -59,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::AllUtils qw(first);
+use List::AllUtils qw(first max);
 use Carp;
 
 =head2 get_bugs
@@ -201,6 +201,9 @@ my %_get_bugs_common_options =
      usertags  => {type => HASHREF,
                    optional => 1,
                   },
+     newest    => {type => SCALAR|ARRAYREF,
+                  optional => 1,
+                 },
      schema => {type     => OBJECT,
                 optional => 1,
                },
@@ -404,7 +407,7 @@ state $_get_bugs_by_idx_options =
    {hash_slice(%_get_bugs_common_options,
                (qw(package submitter severity tag archive),
                 qw(owner src maint bugs correspondent),
-                qw(affects usertags))
+                qw(affects usertags newest))
               )
    };
 sub get_bugs_by_idx{
@@ -420,7 +423,13 @@ sub get_bugs_by_idx{
               die "Can't handle empty maint (unmaintained packages) in get_bugs_by_idx";
          }
      }
-
+     if ($param{newest}) {
+        my $newest_bug = newest_bug();
+        my @bugs = ($newest_bug - max(make_list($param{newest})) + 1) .. $newest_bug;
+        $param{bugs} = [exists $param{bugs}?make_list($param{bugs}):(),
+                        @bugs,
+                       ];
+     }
      # We handle src packages, maint and maintenc by mapping to the
      # appropriate binary packages, then removing all packages which
      # don't match all queries
@@ -492,7 +501,7 @@ state $_get_bugs_by_db_options =
    {hash_slice(%_get_bugs_common_options,
                (qw(package submitter severity tag archive),
                 qw(owner src maint bugs correspondent),
-                qw(affects usertags))
+                qw(affects usertags newest))
               ),
     schema => {type     => OBJECT,
               },
@@ -506,10 +515,7 @@ sub get_bugs_by_db{
      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({'severity.severity' =>
                            [make_list($param{severity})],
@@ -526,17 +532,35 @@ sub get_bugs_by_db{
                               );
          }
      }
+     if (exists $param{newest}) {
+        $rs =
+            $rs->search({},
+                       {order_by => {-desc => 'me.creation'},
+                        rows => max(make_list($param{newest})),
+                       },
+                       );
+     }
      if (exists $param{correspondent}) {
-         $rs = $rs->search({'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}) {
         my @aff_list = make_list($param{affects});
+        s/^src:// foreach @aff_list;
          $rs = $rs->search({-or => {'bin_pkg.pkg' =>
                                    [@aff_list],
                                    'src_pkg.pkg' =>
@@ -552,8 +576,10 @@ sub get_bugs_by_db{
                           );
      }
      if (exists $param{package}) {
-         $rs = $rs->search({'bin_pkg.pkg' =>
-                           [make_list($param{package})],
+         $rs = $rs->search({-or => {'bin_pkg.pkg' =>
+                                   [make_list($param{package})],
+                                   'me.unknown_packages' =>
+                                   [make_list($param{package})]},
                           },
                           {join => {bug_binpackages => 'bin_pkg'}});
      }
@@ -583,7 +609,7 @@ sub get_bugs_by_db{
         $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},
+                                  { -in => $src_pkgs_rs->get_column('id')->as_query},
                                   },
                           },
                          {join => ['bug_binpackages',
@@ -595,28 +621,25 @@ sub get_bugs_by_db{
         # 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'],
+            search({'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'],
+            $s->resultset('BinPkgSrcPkg')->
+            search({'src_pkg.pkg' => [make_list($param{src})],
+                   },
+                  {columns => ['bin_pkg'],
+                   join => ['src_pkg'],
+                   group_by => ['bin_pkg'],
                   });
          $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' =>
+                                  { -in => $bin_pkgs_rs->get_column('bin_pkg')->as_query},
+                                   'bug_srcpackages.src_pkg' =>
+                                  { -in => $src_pkgs_rs->get_column('id')->as_query},
+                                   'me.unknown_packages' =>
                                    [make_list($param{src})],
                                   },
                           },
@@ -675,6 +698,13 @@ sub get_bugs_flatfile{
                               spec   => $_get_bugs_flatfile_options
                              );
      my $flatfile;
+     if ($param{newest}) {
+        my $newest_bug = newest_bug();
+        my @bugs = ($newest_bug - max(make_list($param{newest})) + 1) .. $newest_bug;
+        $param{bugs} = [exists $param{bugs}?make_list($param{bugs}):(),
+                        @bugs,
+                       ];
+     }
      if ($param{archive}) {
          $flatfile = IO::File->new("$config{spool_dir}/index.archive", 'r')
               or die "Unable to open $config{spool_dir}/index.archive for reading: $!";