]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/DB/ResultSet/Bug.pm
503fe7e5761a35a218cbc65404defb75428cad25
[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 __PACKAGE__->load_components('Helper::ResultSet');
27
28 use Debbugs::DB::Util qw(select_one);
29
30 use List::MoreUtils qw(natatime);
31
32
33 =over
34
35 =item quick_insert_bugs
36
37      $s->result_set('Bug')->quick_insert_bugs(@bugs);
38
39 Quickly insert a set of bugs (without any useful information, like subject,
40 etc). This should probably only be called when inserting bugs in the database
41 for first time.
42
43 =cut
44
45
46 sub quick_insert_bugs {
47     my ($self,@bugs) = @_;
48
49     my $it = natatime 2000, @bugs;
50
51     while (my @b = $it->()) {
52         $self->result_source->schema->
53             txn_do(sub{
54                        for my $b (@b) {
55                            $self->quick_insert_bug($b);
56                        }
57                    });
58     }
59 }
60
61 =item quick_insert_bug
62
63      $s->result_set('Bug')->quick_insert_bug($bug);
64
65 Quickly insert a single bug (called by quick_insert_bugs). You should probably
66 actually be calling C<Debbugs::DB::Load::load_bug> instead of this function.
67
68 =cut
69
70 sub quick_insert_bug {
71     my ($self,$bug) = @_;
72     return $self->result_source->schema->storage->
73         dbh_do(sub {
74                    my ($s,$dbh,$b) = @_;
75                    select_one($dbh,<<'SQL',$b);
76 INSERT INTO bug (id,subject,severity) VALUES (?,'',1)
77 ON CONFLICT (id) DO NOTHING RETURNING id;
78 SQL
79                },
80                $bug
81               );
82
83 }
84
85
86 =back
87
88 =cut
89
90
91 1;
92
93 __END__