From: Don Armstrong Date: Sun, 26 Feb 2017 21:32:06 +0000 (-0800) Subject: preload bugs on initial insert X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=d7bda9dac45d437e0f5297e0f09be5f70269c9c3;p=debbugs.git preload bugs on initial insert --- diff --git a/Debbugs/DB/ResultSet/Bug.pm b/Debbugs/DB/ResultSet/Bug.pm new file mode 100644 index 00000000..5dbd5aa5 --- /dev/null +++ b/Debbugs/DB/ResultSet/Bug.pm @@ -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 . +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 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__ diff --git a/bin/debbugs-loadsql b/bin/debbugs-loadsql index 3ebb87fc..c9182667 100755 --- a/bin/debbugs-loadsql +++ b/bin/debbugs-loadsql @@ -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',