[Bps-public-commit] smokingit branch, master, updated. 1f829e61e520b974dbe0b5f5ac701beb8665d4cb

Alex Vandiver alexmv at bestpractical.com
Mon Jan 31 23:03:52 EST 2011


The branch, master has been updated
       via  1f829e61e520b974dbe0b5f5ac701beb8665d4cb (commit)
       via  0e49f7cd0367e743548bbb6f462408f2c0cd3d3d (commit)
       via  12cc6173af0b49c0ad3b37cebf5c5e43b7051f34 (commit)
       via  960485e7ae0890ff733e06b3221557eb3b264de3 (commit)
       via  0aad0cd5626a28fdd47024877c1ee47bc42dbf62 (commit)
      from  01f6dcfa6b1502772b1ae6971af44087350815c6 (commit)

Summary of changes:
 lib/Smokingit/Dispatcher.pm    |    3 +-
 lib/Smokingit/Model/Branch.pm  |   33 +++++++++++++++++--
 lib/Smokingit/Model/Commit.pm  |   69 +++++++++++++++++++++------------------
 lib/Smokingit/Model/Project.pm |    1 +
 lib/Smokingit/View/Branch.pm   |    1 +
 lib/Smokingit/View/Project.pm  |    7 ++--
 6 files changed, 74 insertions(+), 40 deletions(-)

- Log -----------------------------------------------------------------
commit 0aad0cd5626a28fdd47024877c1ee47bc42dbf62
Author: Alex Vandiver <alex at chmrr.net>
Date:   Mon Jan 31 23:01:00 2011 -0500

    Make better use of indexes by marking SHAs as case-sensitive

diff --git a/lib/Smokingit/Dispatcher.pm b/lib/Smokingit/Dispatcher.pm
index ccace64..64c8d8e 100644
--- a/lib/Smokingit/Dispatcher.pm
+++ b/lib/Smokingit/Dispatcher.pm
@@ -121,8 +121,9 @@ under '/*' => [
             return;
         }
 
+        return unless $name =~ /^[A-Fa-f0-9]+$/;
         my $commits = Smokingit::Model::CommitCollection->new;
-        $commits->limit( column => 'sha', operator => 'like', value => "$name%" );
+        $commits->limit( column => 'sha', operator => 'STARTSWITH', value => lc($name) );
         redirect '/test/' . $commits->first->sha
             if $commits->count == 1;
     },
diff --git a/lib/Smokingit/Model/Commit.pm b/lib/Smokingit/Model/Commit.pm
index 4af3913..8a6695e 100644
--- a/lib/Smokingit/Model/Commit.pm
+++ b/lib/Smokingit/Model/Commit.pm
@@ -12,6 +12,7 @@ use Smokingit::Record schema {
         type is 'text',
         is mandatory,
         is unique,
+        is case_sensitive,
         is indexed;
 
     column author =>
@@ -47,10 +48,19 @@ sub create {
     $args{$_} = Jifty::DateTime->from_epoch( $args{$_} )
         for qw/authored_time committed_time/;
 
+    $args{sha} = lc $args{sha};
+    die "Not a full SHA!" unless length $args{sha} == 40;
     my ($ok, $msg) = $self->SUPER::create(%args);
     return ($ok. $msg) unless $ok;
 }
 
+sub load_by_cols {
+    my $self = shift;
+    my %cols = @_;
+    $cols{sha} = lc $cols{sha} if $cols{sha};
+    return $self->SUPER::load_by_cols(%cols);
+}
+
 sub short_sha {
     my $self = shift;
     return substr($self->sha,0,7);

commit 960485e7ae0890ff733e06b3221557eb3b264de3
Author: Alex Vandiver <alex at chmrr.net>
Date:   Mon Jan 31 23:01:52 2011 -0500

    Prefetch commits on smoke results to save on queries

diff --git a/lib/Smokingit/Model/Project.pm b/lib/Smokingit/Model/Project.pm
index 98d2b72..05c063d 100644
--- a/lib/Smokingit/Model/Project.pm
+++ b/lib/Smokingit/Model/Project.pm
@@ -102,6 +102,7 @@ sub planned_tests {
         value => "NULL"
     );
     $tests->limit( column => "project_id", value => $self->id );
+    $tests->prefetch( name => "commit" );
     my @tests = @{ $tests->items_array_ref };
     @tests = sort { $a->gearman_status->known       <=>  $b->gearman_status->known
                 or  $b->gearman_status->running     <=>  $a->gearman_status->running
diff --git a/lib/Smokingit/View/Project.pm b/lib/Smokingit/View/Project.pm
index 65fa73f..a1dfb51 100644
--- a/lib/Smokingit/View/Project.pm
+++ b/lib/Smokingit/View/Project.pm
@@ -44,6 +44,7 @@ template '/project' => page {
             value => "NULL"
         );
         $tests->limit( column => "project_id", value => get('project')->id );
+        $tests->prefetch( name => "commit" );
         $tests->order_by( { column => "submitted_at", order  => "desc" },
                           { column => "id",           order  => "desc" } );
         $tests->rows_per_page(10);

commit 12cc6173af0b49c0ad3b37cebf5c5e43b7051f34
Author: Alex Vandiver <alex at chmrr.net>
Date:   Mon Jan 31 23:02:26 2011 -0500

    Save on smoke_result loads during commit->status

diff --git a/lib/Smokingit/View/Project.pm b/lib/Smokingit/View/Project.pm
index a1dfb51..6bd94f3 100644
--- a/lib/Smokingit/View/Project.pm
+++ b/lib/Smokingit/View/Project.pm
@@ -54,7 +54,7 @@ template '/project' => page {
                 class is "commitlist";
                 h2 { "Recent tests" };
                 while (my $test = $tests->next) {
-                    my ($status, $msg) = $test->commit->status($test->configuration);
+                    my ($status, $msg) = $test->commit->status($test);
                     div {
                         class is "commit $status";
                         hyperlink(
@@ -83,7 +83,7 @@ template '/project' => page {
                 class is "commitlist";
                 h2 { "Planned tests" };
                 for my $test (@planned) {
-                    my ($status, $msg, $in) = $test->commit->status($test->configuration);
+                    my ($status, $msg, $in) = $test->commit->status($test);
                     div {
                         class is "commit $status";
                         span {

commit 0e49f7cd0367e743548bbb6f462408f2c0cd3d3d
Author: Alex Vandiver <alex at chmrr.net>
Date:   Mon Jan 31 23:02:45 2011 -0500

    Warnings avoidance for when branches have gone away

diff --git a/lib/Smokingit/View/Project.pm b/lib/Smokingit/View/Project.pm
index 6bd94f3..1f955fa 100644
--- a/lib/Smokingit/View/Project.pm
+++ b/lib/Smokingit/View/Project.pm
@@ -70,7 +70,7 @@ template '/project' => page {
                             url     => "/test/".$test->commit->sha."/".$test->configuration->name,
                             label   => $test->commit->short_sha,
                         );
-                        outs( " on ".$test->from_branch->name . " using ".$test->configuration->name );
+                        outs( " on ".($test->from_branch->name || "?") . " using ".$test->configuration->name );
                     }
                 }
             };

commit 1f829e61e520b974dbe0b5f5ac701beb8665d4cb
Author: Alex Vandiver <alex at chmrr.net>
Date:   Mon Jan 31 23:03:10 2011 -0500

    Prefetch smoke results when listing commits
    
    This saves 4 queries/sha on the branch view page

diff --git a/lib/Smokingit/Model/Branch.pm b/lib/Smokingit/Model/Branch.pm
index ed3552d..bb78e49 100644
--- a/lib/Smokingit/Model/Branch.pm
+++ b/lib/Smokingit/Model/Branch.pm
@@ -135,10 +135,35 @@ sub commit_list {
 
     my $first = $self->first_commit->sha;
     my $last = $self->current_commit->sha;
-    my @revs = map {chomp; $_} `git rev-list ^$first $last`;
-    push @revs, map {chomp; $_} `git rev-list $first --max-count=11`;
-
-    return map {$self->project->sha($_)} @revs;
+    my @revs = map {chomp; $_} `git rev-list ^$first $last --max-count=50`;
+    my $left = 50 - @revs; $left = 11 if $left > 11;
+    push @revs, map {chomp; $_} `git rev-list $first --max-count=$left`
+        if $left > 0;
+
+    my $commits = Smokingit::Model::CommitCollection->new;
+    $commits->limit( column => "project_id", value => $self->project->id );
+    $commits->limit( column => "sha", operator => "IN", value => \@revs);
+    my $results = $commits->join(
+        type    => "left",
+        alias1  => "main",
+        column1 => "id",
+        table2  => "smoke_results",
+        column2 => "commit_id",
+        is_distinct => 1,
+    );
+    $commits->limit(
+        leftjoin => $results,
+        column   => "project_id",
+        value    => $self->project->id
+    );
+    $commits->prefetch(
+        name => "smoke_results",
+        alias => $results,
+        class => "Smokingit::Model::SmokeResultCollection",
+    );
+    my %commits;
+    $commits{$_->sha} = $_ while $_ = $commits->next;
+    return map $commits{$_}, @revs;
 }
 
 sub branchpoint {
diff --git a/lib/Smokingit/Model/Commit.pm b/lib/Smokingit/Model/Commit.pm
index 8a6695e..bd65d71 100644
--- a/lib/Smokingit/Model/Commit.pm
+++ b/lib/Smokingit/Model/Commit.pm
@@ -66,11 +66,6 @@ sub short_sha {
     return substr($self->sha,0,7);
 }
 
-sub is_smoked {
-    my $self = shift;
-    return $self->smoked->count > 0;
-}
-
 sub run_smoke {
     my $self = shift;
     my $config = shift;
@@ -92,6 +87,16 @@ sub run_smoke {
     return $smoke->run_smoke;
 }
 
+sub hash_results {
+    my $self = shift;
+    my $results = $self->prefetched( "smoke_results" );
+    die "$self does not have smoke_results prefetched!"
+        unless $results;
+    $self->{results} = {};
+    $self->{results}{$_->configuration->id} = $_
+        for @{$results->items_array_ref};
+}
+
 sub status {
     my $self = shift;
     my $on = shift;
@@ -101,11 +106,16 @@ sub status {
         if ($on->isa("Smokingit::Model::SmokeResult")) {
             $result = $on;
         } elsif ($on->isa("Smokingit::Model::Configuration")) {
-            $result->load_by_cols(
-                project_id => $self->project->id,
-                configuration_id => $on->id,
-                commit_id => $self->id,
-            );
+            if (exists $self->{results}) {
+                $result = $self->{results}{$on->id}
+                    if exists $self->{results}{$on->id};
+            } else {
+                $result->load_by_cols(
+                    project_id => $self->project->id,
+                    configuration_id => $on->id,
+                    commit_id => $self->id,
+                );
+            }
         } else {
             die "Unknown argument to Smokingit::Model::Commit->status: $on";
         }
@@ -147,10 +157,14 @@ sub status {
         return $self->{status};
     } else {
         my %results;
-        my $smoked = $self->smoked;
-        while (my $s = $smoked->next) {
-            my ($st) = $self->status($s);
-            $results{$st}++;
+        if (exists $self->{results}) {
+            $results{$_}++ for map {$self->status($_)} values %{$self->{results}};
+        } else {
+            my $smoked = Smokingit::Model::SmokeResultCollection->new;
+            $smoked->limit( column => "commit_id", value => $self->id );
+            $smoked->limit( column => "project_id", value => $self->project->id );
+            $results{$self->status($_)}++
+                while $_ = $smoked->next;
         }
         for my $st (qw/broken errors failing todo passing parsefail testing queued/) {
             $self->{status} ||= $st if $results{$st};
@@ -175,25 +189,6 @@ sub long_status {
     return $long{$self->status};
 }
 
-sub smoked {
-    my $self = shift;
-    my $config = shift;
-    if ($config) {
-        my $smoke = Smokingit::Model::SmokeResult->new;
-        $smoke->load_by_cols(
-            project_id => $self->project->id,
-            commit_id => $self->id,
-            configuration_id => $config->id,
-        );
-        return $smoke;
-    } else {
-        my $smoked = Smokingit::Model::SmokeResultCollection->new;
-        $smoked->limit( column => "commit_id", value => $self->id );
-        $smoked->limit( column => "project_id", value => $self->project->id );
-        return $smoked;
-    }
-}
-
 sub parents {
     my $self = shift;
     return map {$self->project->sha($_)} split ' ', $self->_value('parents');
diff --git a/lib/Smokingit/View/Branch.pm b/lib/Smokingit/View/Branch.pm
index b824a6b..f0744ab 100644
--- a/lib/Smokingit/View/Branch.pm
+++ b/lib/Smokingit/View/Branch.pm
@@ -43,6 +43,7 @@ template '/branch' => page {
         id is "branch-commits";
         class is "commitlist biglist";
         for my $commit (@commits) {
+            $commit->hash_results;
             div {
                 {class is "commit ".$commit->status};
                 for my $config (@configs) {

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list