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