]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/DB/ResultSet/Bug.pm
265d4d97b8d82d169bfb00b8b65a5c517e16c84d
[debbugs.git] / Debbugs / DB / ResultSet / Bug.pm
1 # This module is part of debbugs, and is released
2 # under the terms of the GPL version 2, or any later version. See the
3 # file README and COPYING for more information.
4 # Copyright 2017 by Don Armstrong <don@donarmstrong.com>.
5 use utf8;
6 package Debbugs::DB::ResultSet::Bug;
7
8 =head1 NAME
9
10 Debbugs::DB::ResultSet::Bug - Bug result set operations
11
12 =head1 SYNOPSIS
13
14
15
16 =head1 DESCRIPTION
17
18
19
20 =cut
21
22 use strict;
23 use warnings;
24
25 use base 'DBIx::Class::ResultSet';
26
27 use Debbugs::DB::Util qw(select_one);
28
29 use List::AllUtils qw(natatime);
30
31
32 =over
33
34 =item quick_insert_bugs
35
36      $s->result_set('Bug')->quick_insert_bugs(@bugs);
37
38 Quickly insert a set of bugs (without any useful information, like subject,
39 etc). This should probably only be called when inserting bugs in the database
40 for first time.
41
42 =cut
43
44
45 sub quick_insert_bugs {
46     my ($self,@bugs) = @_;
47
48     my $it = natatime 2000, @bugs;
49
50     while (my @b = $it->()) {
51         $self->result_source->schema->
52             txn_do(sub{
53                        for my $b (@b) {
54                            $self->quick_insert_bug($b);
55                        }
56                    });
57     }
58 }
59
60 =item quick_insert_bug
61
62      $s->result_set('Bug')->quick_insert_bug($bug);
63
64 Quickly insert a single bug (called by quick_insert_bugs). You should probably
65 actually be calling C<Debbugs::DB::Load::load_bug> instead of this function.
66
67 =cut
68
69 sub quick_insert_bug {
70     my ($self,$bug) = @_;
71     return $self->result_source->schema->storage->
72         dbh_do(sub {
73                    my ($s,$dbh,$b) = @_;
74                    select_one($dbh,<<'SQL',$b);
75 INSERT INTO bug (id,subject,severity) VALUES (?,'',1)
76 ON CONFLICT (id) DO NOTHING RETURNING id;
77 SQL
78                },
79                $bug
80               );
81
82 }
83
84
85 =back
86
87 =cut
88
89
90 1;
91
92 __END__