]> git.donarmstrong.com Git - debbugs.git/commitdiff
preload bugs on initial insert
authorDon Armstrong <don@donarmstrong.com>
Sun, 26 Feb 2017 21:32:06 +0000 (13:32 -0800)
committerDon Armstrong <don@donarmstrong.com>
Sun, 26 Feb 2017 21:32:06 +0000 (13:32 -0800)
Debbugs/DB/ResultSet/Bug.pm [new file with mode: 0644]
bin/debbugs-loadsql

diff --git a/Debbugs/DB/ResultSet/Bug.pm b/Debbugs/DB/ResultSet/Bug.pm
new file mode 100644 (file)
index 0000000..5dbd5aa
--- /dev/null
@@ -0,0 +1,91 @@
+# This module is part of debbugs, and is released
+# under the terms of the GPL version 2, or any later version. See the
+# file README and COPYING for more information.
+# Copyright 2017 by Don Armstrong <don@donarmstrong.com>.
+use utf8;
+package Debbugs::DB::ResultSet::Bug;
+
+=head1 NAME
+
+Debbugs::DB::ResultSet::Bug - Bug result set operations
+
+=head1 SYNOPSIS
+
+
+
+=head1 DESCRIPTION
+
+
+
+=cut
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::ResultSet';
+use Debbugs::DB::Util qw(select_one);
+
+use List::MoreUtils qw(natatime);
+
+
+=over
+
+=item quick_insert_bugs
+
+     $s->result_set('Bug')->quick_insert_bugs(@bugs);
+
+Quickly insert a set of bugs (without any useful information, like subject,
+etc). This should probably only be called when inserting bugs in the database
+for first time.
+
+=cut
+
+
+sub quick_insert_bugs {
+    my ($self,@bugs) = @_;
+
+    my $it = natatime 300, @bugs;
+
+    while (my @b = $it->()) {
+       $self->result_source->schema->
+           txn_do(sub{
+                      for my $b (@b) {
+                          $self->quick_insert_bug($b);
+                      }
+                  });
+    }
+}
+
+=item quick_insert_bug
+
+     $s->result_set('Bug')->quick_insert_bug($bug);
+
+Quickly insert a single bug (called by quick_insert_bugs). You should probably
+actually be calling C<Debbugs::DB::Load::load_bug> instead of this function.
+
+=cut
+
+sub quick_insert_bug {
+    my ($self,$bug) = @_;
+    return $self->result_source->schema->storage->
+       dbh_do(sub {
+                  my ($s,$dbh,$b) = @_;
+                  select_one($dbh,<<'SQL',$b);
+INSERT INTO bug (id,subject,severity) VALUES (?,'',1)
+ON CONFLICT (id) DO NOTHING RETURNING id;
+SQL
+              },
+              $bug
+             );
+
+}
+
+
+=back
+
+=cut
+
+
+1;
+
+__END__
index 3ebb87fcf9409452599e483d35876e57057ef396..c91826677ffb5d666019ab85c3ef37ff0c7f8e98 100755 (executable)
@@ -144,6 +144,7 @@ $DEBUG = $options{debug};
 
 my %subcommands =
     ('bugs' => {function => \&add_bugs,
+               arguments => {'preload' => 0},
                },
      'versions' => {function => \&add_versions,
                    },
@@ -236,6 +237,17 @@ sub add_bugs {
     my %severities;
     my %queue;
 
+    if ($opts->{preload}) {
+       my @bugs;
+       walk_bugs([(@{$argv}?@{$argv} : $initialdir)],
+                 undef,
+                 'summary',
+                 undef,
+                 sub {
+                     push @bugs,shift;
+                 });
+       $s->resultset('Bug')->quick_insert_bugs(@bugs);
+    }
     walk_bugs([(@{$argv}?@{$argv} : $initialdir)],
               $p,
               'summary',