]> git.donarmstrong.com Git - debbugs.git/blobdiff - bin/debbugs-loadsql
walk through multiple bugs at a time
[debbugs.git] / bin / debbugs-loadsql
index 957d190ff3a19134b5cefd28100f70de508cf9e8..277ac2b586f1d2ddb952aea181510caf37eaef3c 100755 (executable)
@@ -17,10 +17,13 @@ debbugs-loadsql -- load debbugs sql database
 
 =head1 SYNOPSIS
 
-debbugs-loadsql [options]
+debbugs-loadsql [options] [subcommand]
 
+ Subcommands:
+  bugs help versions configuration
+  suites logs packages debinfo
  Options:
-  --quick, -q only load changed bugs
+  --quick, -q only load changed things
   --progress Show progress bar
   --service, -s service name
   --sysconfdir, -c postgresql service config dir
@@ -37,15 +40,45 @@ Display this manual
 
 =head2 bugs
 
-Add bugs
+Add bugs (subject, number, etc) to the database
+
+   --preload create all bugs first, then add information
 
 =head2 versions
 
-Add versions
+Add version descendant information (which version is based on which version) to
+the database
 
 =head2 maintainers
 
-Add source maintainers
+Add source maintainers to the BTS
+
+=head2 configuration
+
+Add debbugs configuration information (tags, severity, etc)
+
+=head2 suites
+
+Add suite information from ftp distribution
+
+  --ftpdists location of FTP mirror
+
+=head2 logs
+
+Add bug logs
+
+=head2 packages
+
+Add package information from the ftp archive
+
+  --ftpdists location of FTP mirror
+  --suites Suite to operate on
+
+=head2 debinfo
+
+Add package information from a debinfo file
+
+  --null -0 names of debinfo files are null separated
 
 =head1 OPTIONS
 
@@ -104,7 +137,7 @@ use Debbugs::Config qw(:config);
 use Debbugs::Status qw(read_bug split_status_fields);
 use Debbugs::Log;
 use Debbugs::DB;
-use Debbugs::DB::Load qw(load_bug handle_load_bug_queue :load_package :load_suite);
+use Debbugs::DB::Load qw(:load_bug :load_package :load_suite);
 use DateTime;
 use File::stat;
 use File::Basename;
@@ -113,6 +146,7 @@ use IO::Dir;
 use IO::File;
 use IO::Uncompress::AnyUncompress;
 use Encode qw(decode_utf8);
+use List::MoreUtils qw(natatime);
 
 my %options =
     (debug           => 0,
@@ -144,6 +178,7 @@ $DEBUG = $options{debug};
 
 my %subcommands =
     ('bugs' => {function => \&add_bugs,
+               arguments => {'preload' => 0},
                },
      'versions' => {function => \&add_versions,
                    },
@@ -236,36 +271,56 @@ sub add_bugs {
     my %severities;
     my %queue;
 
+    if ($opts->{preload}) {
+       my @bugs;
+       walk_bugs([(@{$argv}?@{$argv} : $initialdir)],
+                 undef,
+                 'summary',
+                 undef,
+                 sub {
+                   push @bugs,@_;
+                 },
+                 10000
+                );
+       $s->resultset('Bug')->quick_insert_bugs(@bugs);
+    }
     walk_bugs([(@{$argv}?@{$argv} : $initialdir)],
               $p,
               'summary',
               $verbose,
               sub {
-                  my $bug = shift;
-                  my $stat = stat(getbugcomponent($bug,'summary',$initialdir));
-                  if (not defined $stat) {
+               my @bugs = @_;
+               my @bugs_to_update;
+               if ($options{quick}) {
+                 for my $bug (@bugs) {
+                   my $stat = stat(getbugcomponent($bug,'summary',$initialdir));
+                   if (not defined $stat) {
                       print STDERR "Unable to stat $bug $!\n";
                       next;
+                   }
+                   my $rs = $s->resultset('Bug')->search({bug=>$bug})->single();
+                   next if defined $rs and $stat->mtime < $rs->last_modified()->epoch();
+                   push @bugs_to_update, $bug;
                   }
-                  if ($options{quick}) {
-                      my $rs = $s->resultset('Bug')->search({bug=>$bug})->single();
-                      next if defined $rs and $stat->mtime < $rs->last_modified()->epoch();
-                  }
-                  my $data = read_bug(bug => $bug,
-                                      location => $initialdir);
-                  eval {
-                      load_bug(db => $s,
-                               data => split_status_fields($data),
-                               tags => \%tags,
-                               severities => \%severities,
-                               queue => \%queue);
-                  };
-                  if ($@) {
-                      use Data::Dumper;
-                      print STDERR Dumper($data) if $DEBUG;
-                      die "failure while trying to load bug $bug\n$@";
-                  }
-              }
+               } else {
+                 @bugs_to_update = @bugs;
+               }
+               eval {
+                 $s->txn_do(sub {
+                              for my $bug (@bugs) {
+                                load_bug(db => $s,
+                                         bug => $bug,
+                                         tags => \%tags,
+                                         severities => \%severities,
+                                         queue => \%queue);
+                              }
+                            });
+               };
+               if ($@) {
+                 die "failure while trying to load bug: $@";
+               }
+              },
+             50
              );
     handle_load_bug_queue(db => $s,
                           queue => \%queue);
@@ -387,42 +442,36 @@ sub add_maintainers {
 
     my $s = db_connect($options);
     my $maintainers = getsourcemaintainers();
-    $p->target(scalar keys %{$maintainers}) if $p;
-    for my $pkg (keys %{$maintainers}) {
-        my $maint = $maintainers->{$pkg};
-        # see if a maintainer already exists; if so, we don't do
-        # anything here
-        my $maint_r = $s->resultset('Maintainer')->
-            find({name => $maint});
-        if (not defined $maint_r) {
-            # get e-mail address of maintainer
-            my $addr = getparsedaddrs($maint);
-            my $e_mail = $addr->address();
-            my $full_name = $addr->phrase();
-            $full_name =~ s/^\"|\"$//g;
-            $full_name =~ s/^\s+|\s+$//g;
-            # find correspondent
-            my $correspondent = $s->resultset('Correspondent')->
-                find_or_create({addr => $e_mail});
-            if (length $full_name) {
-                my $c_full_name = $correspondent->find_or_create_related('correspondent_full_names',
-                                                                        {full_name => $full_name}) if length $full_name;
-                $c_full_name->update({last_seen => 'NOW()'});
-            }
-            $maint_r =
-                $s->resultset('Maintainer')->
-                find_or_create({name => $maint,
-                                correspondent => $correspondent,
-                               });
-        }
-        # add the maintainer to the source package for packages with
-        # no maintainer
-        $s->txn_do(sub {
-                      $s->resultset('SrcPkg')->search({pkg => $pkg})->
-                          search_related_rs('src_vers',{ maintainer => undef})->
-                          update_all({maintainer => $maint_r->id()});
-                  });
-        $p->update() if $p;
+    $p->target(2) if $p;
+    ## get all of the maintainers, and add the missing ones
+    my $maints = $s->resultset('Maintainer')->
+       get_maintainers(values %{$maintainers});
+    $p->update();
+    my @svs = $s->resultset('SrcVer')->
+       search({maintainer => undef
+              },
+             {join => 'src_pkg',
+              group_by => 'me.src_pkg, src_pkg.pkg',
+              result_class => 'DBIx::Class::ResultClass::HashRefInflator',
+              columns => [qw(me.src_pkg src_pkg.pkg)],
+             }
+             )->all();
+    $p->target(2+@svs) if $p;
+    $p->update() if $p;
+    for my $sv (@svs) {
+       if (exists $maintainers->{$sv->{src_pkg}{pkg}}) {
+           my $pkg = $sv->{src_pkg}{pkg};
+           my $maint = $maints->
+              {$maintainers->{$pkg}};
+           $s->txn_do(sub {$s->resultset('SrcVer')->
+                               search({maintainer => undef,
+                                       'src_pkg.pkg' => $pkg
+                                      },
+                                     {join => 'src_pkg'}
+                                     )->update({maintainer => $maint})
+                                 });
+       }
+       $p->update() if $p;
     }
     $p->remove() if $p;
 }
@@ -434,25 +483,35 @@ sub add_configuration {
 
     # tags
     # add all tags
+    my %tags;
+    for my $tag (@{$config{tags}}) {
+       $tags{$tag} = 1;
+       $s->resultset('Tag')->find_or_create({tag => $tag});
+    }
     # mark obsolete tags
+    for my $tag ($s->resultset('Tag')->search_rs()->all()) {
+       next if exists $tags{$tag->tag};
+       $tag->obsolete(1);
+       $tag->update;
+    }
 
     # severities
     my %sev_names;
-    my $order = 0;
-    for my $sev_name (@{$config{severities}}) {
+    my $order = -1;
+    for my $sev_name (($config{default_severity},@{$config{severity_list}})) {
         # add all severitites
         my $sev = $s->resultset('Severity')->find_or_create({severity => $sev_name});
         # mark strong severities
         if (grep {$_ eq $sev_name} @{$config{strong_severities}}) {
             $sev->strong(1);
         }
-        $sev->order($order);
+        $sev->ordering($order);
         $sev->update();
         $order++;
         $sev_names{$sev_name} = 1;
     }
     # mark obsolete severities
-    for my $sev ($s->resultset('Severity')->find()) {
+    for my $sev ($s->resultset('Severity')->search_rs()->all()) {
         next if exists $sev_names{$sev->severity()};
         $sev->obsolete(1);
         $sev->update();
@@ -503,7 +562,16 @@ sub add_logs {
               $verbose,
               sub {
                   my $bug = shift;
-                  eval { 
+                 my $stat = stat(getbugcomponent($bug,'log',$initialdir));
+                  if (not defined $stat) {
+                      print STDERR "Unable to stat $bug $!\n";
+                      next;
+                  }
+                  if ($options{quick}) {
+                      my $rs = $s->resultset('Bug')->search({bug=>$bug})->single();
+                      next if defined $rs and $stat->mtime < $rs->last_modified()->epoch();
+                  }
+                  eval {
                       load_bug_log(db => $s,
                                    bug => $bug);
                   };
@@ -676,12 +744,13 @@ sub read_release_file {
 }
 
 sub walk_bugs {
-    my ($dirs,$p,$what,$verbose,$sub) = @_;
+    my ($dirs,$p,$what,$verbose,$sub,$n) = @_;
     my @dirs = @{$dirs};
     my $tot_dirs = @dirs;
     my $done_dirs = 0;
     my $avg_subfiles = 0;
     my $completed_files = 0;
+    $n //= 1;
     while (my $dir = shift @dirs) {
         printf "Doing dir %s ...\n", $dir if $verbose;
 
@@ -701,11 +770,13 @@ sub walk_bugs {
         $avg_subfiles = ($avg_subfiles * $done_dirs + @list) / ($done_dirs+1);
         $done_dirs += 1;
 
-        for my $bug (@list) {
-            $completed_files++;
-            $p->update($completed_files) if $p;
-            print "Up to $completed_files bugs...\n" if ($completed_files % 100 == 0 && $verbose);
-            $sub->($bug);
+       my $it = natatime $n,@list;
+       while (my @bugs = $it->()) {
+         $sub->(@bugs);
+         $completed_files += scalar @bugs;
+         $p->update($completed_files) if $p;
+         print "Up to $completed_files bugs...\n"
+           if ($completed_files % 100 == 0 && $verbose);
         }
     }
     $p->remove() if $p;