]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/DB/ResultSet/BugStatusCache.pm
278d0e615c3b8cdfdf67f820ae400e1dba7d83dc
[debbugs.git] / Debbugs / DB / ResultSet / BugStatusCache.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::BugStatusCache;
7
8 =head1 NAME
9
10 Debbugs::DB::ResultSet::BugStatusCache - 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 update_bug_status
36
37         $s->resultset('BugStatusCache')->
38             update_bug_status($bug->id,
39                               $suite->{id},
40                               undef,
41                               $presence,
42                               );
43
44 Update the status information for a particular bug at a particular suite
45
46 =cut
47
48 sub update_bug_status {
49     my ($self,@args) = @_;
50     return $self->result_source->schema->storage->
51         dbh_do(sub {
52                    my ($s,$dbh,$bug,$suite,$arch,$status,$modified,$asof) = @_;
53                    select_one($dbh,<<'SQL',$bug,$suite,$arch,$status,$status);
54 INSERT INTO bug_status_cache AS bsc
55 (bug,suite,arch,status,modified,asof)
56 VALUES (?,?,?,?,NOW(),NOW())
57 ON CONFLICT (bug,COALESCE(suite,0),COALESCE(arch,0)) DO
58 UPDATE
59  SET asof=NOW(),modified=CASE WHEN bsc.status=? THEN bsc.modified ELSE NOW() END
60 RETURNING status;
61 SQL
62                },
63            @args
64               );
65 }
66
67
68 =back
69
70 =cut
71
72
73 1;
74
75 __END__