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