]> git.donarmstrong.com Git - debbugs.git/blobdiff - Debbugs/DB/Load.pm
use get_*_id in load_debinfo; handle -0 correctly there too
[debbugs.git] / Debbugs / DB / Load.pm
index dfc1db9869b0a400d8d3427ad3026d7ee900d319..86662f3011c8f9678ea6fccafc8af07bd5c70ba3 100644 (file)
@@ -101,6 +101,10 @@ sub load_bug {
                                                      },
                                        queue => {type => HASHREF,
                                                  optional => 1},
+                                      packages => {type => HASHREF,
+                                                   default => sub {return {}},
+                                                   optional => 1,
+                                                  },
                                       });
     my $s = $param{db};
     if (not exists $param{data} and not exists $param{bug}) {
@@ -119,8 +123,8 @@ sub load_bug {
         $queue = {};
     }
     my %tags;
-    my $s_data = split_status_fields($data);
-    for my $tag (make_list($s_data->{keywords})) {
+    $data = split_status_fields($data);
+    for my $tag (make_list($data->{keywords})) {
        next unless defined $tag and length $tag;
        # this allows for invalid tags. But we'll use this to try to
        # find those bugs and clean them up
@@ -171,8 +175,37 @@ sub load_bug {
     }
     my $b = $s->resultset('Bug')->update_or_create($bug) or
         die "Unable to update or create bug $bug->{id}";
-     $s->txn_do(sub {
-                  for my $ff (qw(found fixed)) {
+    $s->txn_do(sub {
+                $b->set_related_packages('binpackages',
+                                         [grep {defined $_ and
+                                                  length $_ and $_ !~ /^src:/}
+                                          make_list($data->{package})],
+                                         $param{packages},
+                                        );
+                $b->set_related_packages('srcpackages',
+                                         [map {s/src://;
+                                                $_}
+                                           grep {defined $_ and
+                                                  $_ =~ /^src:/}
+                                          make_list($data->{package})],
+                                         $param{packages},
+                                        );
+                $b->set_related_packages('affects_binpackages',
+                                         [grep {defined $_ and
+                                                  length $_ and $_ !~ /^src:/}
+                                          make_list($data->{affects})
+                                         ],
+                                         $param{packages},
+                                        );
+                $b->set_related_packages('affects_srcpackages',
+                                         [map {s/src://;
+                                                $_}
+                                           grep {defined $_ and
+                                                  $_ =~ /^src:/}
+                                          make_list($data->{affects})],
+                                         $param{packages},
+                                        );
+                for my $ff (qw(found fixed)) {
                       my @elements = $s->resultset('BugVer')->search({bug => $data->{bug_num},
                                                                       found  => $ff eq 'found'?1:0,
                                                                      });
@@ -412,23 +445,59 @@ Commands to handle src and package version loading from debinfo files
 =cut
 
 sub load_debinfo {
-    my ($schema,$binname, $binver, $binarch, $srcname, $srcver) = @_;
-    my $sp = $schema->resultset('SrcPkg')->find_or_create({pkg => $srcname});
-    my $sv = $schema->resultset('SrcVer')->find_or_create({src_pkg=>$sp->id(),
-                                                           ver => $srcver});
-    my $arch = $schema->resultset('Arch')->find_or_create({arch => $binarch});
-    my $bp = $schema->resultset('BinPkg')->find_or_create({pkg => $binname});
-    $schema->resultset('BinVer')->find_or_create({bin_pkg_id => $bp->id(),
-                                                  src_ver_id => $sv->id(),
-                                                  arch_id    => $arch->id(),
-                                                  ver        => $binver,
-                                                 });
+    my ($s,$binname, $binver, $binarch, $srcname, $srcver,$ct_date,$cache) = @_;
+    $cache //= {};
+    my $sp;
+    if (not defined $cache->{sp}{$srcname}) {
+        $cache->{sp}{$srcname} =
+            $s->resultset('SrcPkg')->find_or_create({pkg => $srcname});
+    }
+    $sp = $cache->{sp}{$srcname};
+    # update the creation date if the data we have is earlier
+    if (defined $ct_date and
+        (not defined $sp->creation or
+         $ct_date < $sp->creation)) {
+        $sp->creation($ct_date);
+        $sp->last_modified(DateTime->now);
+        $sp->update;
+    }
+    my $sv;
+    if (not defined $cache->{sv}{$srcname}{$srcver}) {
+        $cache->{sv}{$srcname}{$srcver} =
+            $s->resultset('SrcVer')->
+            find_or_create({src_pkg =>$sp->id(),
+                            ver => $srcver});
+    }
+    $sv = $cache->{sv}{$srcname}{$srcver};
+    if (defined $ct_date and
+        (not defined $sv->upload_date() or $ct_date < $sv->upload_date())) {
+        $sv->upload_date($ct_date);
+        $sv->update;
+    }
+    my $arch;
+    if (not defined $cache->{arch}{$binarch}) {
+        $cache->{arch}{$binarch} =
+            $s->resultset('Arch')->
+            find_or_create({arch => $binarch},
+                          {result_class => 'DBIx::Class::ResultClass::HashRefInflator'},
+                          )->{id};
+    }
+    $arch = $cache->{arch}{$binarch};
+    my $bp;
+    if (not defined $cache->{bp}{$binname}) {
+        $cache->{bp}{$binname} =
+            $s->resultset('BinPkg')->
+            get_bin_pkg_id($binname);
+    }
+    $bp = $cache->{bp}{$binname};
+    $s->resultset('BinVer')->
+        get_bin_ver_id($bp,$binver,$arch,$sv->id());
 }
 
 
 =back
 
-=head Packages
+=head2 Packages
 
 =over
 
@@ -542,8 +611,15 @@ sub load_packages {
     }
     # remove associations for packages not in this suite
     if (@sa_to_del) {
-       $schema->resultset('SrcAssociation')->
-           search_rs({id => \@sa_to_del})->delete();
+        $it = natatime 1000, @sa_to_del;
+        while (my @v = $it->()) {
+            $schema->
+                txn_do(sub {
+                           $schema->resultset('SrcAssociation')->
+                               search_rs({id => \@v})->
+                               delete();
+                       });
+        }
     }
     # update packages in this suite to have a modification time of now
     $schema->resultset('SrcAssociation')->
@@ -606,8 +682,15 @@ sub load_packages {
                   scalar @v) if defined $p;
     }
     if (@bin_to_del) {
-       $schema->resultset('BinAssociation')->
-           search_rs({id => \@bin_to_del})->delete();
+        $it = natatime 1000, @bin_to_del;
+        while (my @v = $it->()) {
+            $schema->
+                txn_do(sub {
+                           $schema->resultset('BinAssociation')->
+                               search_rs({id => \@v})->
+                               delete();
+                       });
+        }
     }
     $schema->resultset('BinAssociation')->
        search_rs({suite => $suite_id})->
@@ -620,7 +703,7 @@ sub load_packages {
 
 =cut
 
-=head Suites
+=head2 Suites
 
 =over
 
@@ -654,3 +737,7 @@ sub load_suite {
 
 
 __END__
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End: