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