New server, FileBin instead of $ENV{BFConfDir}, and custom Captcha
[buildfarm-server.git] / cgi-bin / show_history.pl
index f1fa13cd6f8134f7af9ca4d4298a37c1375740bb..c57a61793d4744f6ac4a09281f523d483e770489 100755 (executable)
@@ -1,5 +1,13 @@
 #!/usr/bin/perl
 
+=comment
+
+Copyright (c) 2003-2010, Andrew Dunstan
+
+See accompanying License file for license details
+
+=cut 
+
 use strict;
 use DBI;
 use Template;
@@ -7,9 +15,8 @@ use CGI;
 
 use vars qw($dbhost $dbname $dbuser $dbpass $dbport $template_dir);
 
-
-require "$ENV{BFConfDir}/BuildFarmWeb.pl";
-#require "BuildFarmWeb.pl";
+use FindBin qw($RealBin);
+require "$RealBin/../BuildFarmWeb.pl";
 
 die "no dbname" unless $dbname;
 die "no dbuser" unless $dbuser;
@@ -28,36 +35,55 @@ my $branch = $query->param('br'); $branch =~ s/[^a-zA-Z0-9_ -]//g;
 my $hm = $query->param('hm');  $hm =~ s/[^a-zA-Z0-9_ -]//g;
 $hm = '240' unless $hm =~ /^\d+$/;
 
-# we don't really need to do this join, since we only want
-# one row from buildsystems. but it means we only have to run one
-# query. If it gets heavy we'll split it up and run two
-
-my $statement = <<EOS;
-
-  select (now() at time zone 'GMT')::timestamp(0) - snapshot as when_ago,
-      sysname, snapshot, b.status, stage,
-      operating_system, os_version, compiler, compiler_version, architecture,
-      owner_email
-  from buildsystems s, 
-       build_status b 
-  where name = ?
-        and branch = ?
-        and s.status = 'approved'
-        and name = sysname
-  order by snapshot desc
-  limit $hm
-
-EOS
+my $latest_personality = $db->selectrow_arrayref(q{
+            select os_version, compiler_version
+            from personality
+            where name = ?
+            order by effective_date desc limit 1
+       }, undef, $member);
+
+my $systemdata = q{
+    select operating_system, os_version, compiler, compiler_version, architecture,
+      owner_email, sys_notes_ts::date AS sys_notes_date, sys_notes
+    from buildsystems b
+    where b.status = 'approved'
+        and name = ?
+};
+
+my $statement = qq{
+   with x as 
+   (  select * 
+      from build_status_recent_500
+      where sysname = ? 
+         and branch = ?
+   ) 
+   select (now() at time zone 'GMT')::timestamp(0) - snapshot as when_ago, 
+            sysname, snapshot, status, stage 
+   from x 
+   order by snapshot desc  
+   limit $hm
+}
 ;
 
+my $sth = $db->prepare($systemdata);
+$sth->execute($member);
+my $sysrow = $sth->fetchrow_hashref;
 my $statrows=[];
-my $sth=$db->prepare($statement);
+$sth=$db->prepare($statement);
 $sth->execute($member,$branch);
 while (my $row = $sth->fetchrow_hashref)
 {
+    last unless $sysrow;
+    while (my($k,$v) = each %$sysrow) { $row->{$k} = $v; }
     $row->{owner_email} =~ s/\@/ [ a t ] /;
-       push(@$statrows,$row);
+    if ($latest_personality)
+    {
+       $row->{os_version} = $latest_personality->[0];
+       $row->{compiler_version} = $latest_personality->[1];
+    }
+    push(@$statrows,$row);
 }
+
 $sth->finish;
 
 $db->disconnect;