X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lib%2FDebbugs%2FDB%2FResultSet%2FBug.pm;fp=lib%2FDebbugs%2FDB%2FResultSet%2FBug.pm;h=265d4d97b8d82d169bfb00b8b65a5c517e16c84d;hb=1e6633a3780f4fd53fc4303852e84d13cdad2dc6;hp=0000000000000000000000000000000000000000;hpb=466f7faff129a5699c7674f59900a92aa256175d;p=debbugs.git diff --git a/lib/Debbugs/DB/ResultSet/Bug.pm b/lib/Debbugs/DB/ResultSet/Bug.pm new file mode 100644 index 0000000..265d4d9 --- /dev/null +++ b/lib/Debbugs/DB/ResultSet/Bug.pm @@ -0,0 +1,92 @@ +# 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::AllUtils 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 2000, @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__