From: Alexander Hartmaier Date: Thu, 20 Jan 2011 13:22:55 +0000 (+0100) Subject: optimized is_leaf to not trigger another query if the children releationship is prefe... X-Git-Tag: 0.03003~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ab184e4a4303cde87f3f585ec422f99898a915b4;p=dbsrgits%2FDBIx-Class-Tree.git optimized is_leaf to not trigger another query if the children releationship is prefetched --- diff --git a/Changes b/Changes index ef75b2b..8cdbe24 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,9 @@ Revision history for DBIx::Class::Tree + - Optimized is_leaf to not trigger another query if the children + releationship is prefetched + 0.03002 2010-09-23 - Added various docs - Added ordered ancesors (nebulous) diff --git a/lib/DBIx/Class/Tree/AdjacencyList.pm b/lib/DBIx/Class/Tree/AdjacencyList.pm index e668a38..e14875f 100644 --- a/lib/DBIx/Class/Tree/AdjacencyList.pm +++ b/lib/DBIx/Class/Tree/AdjacencyList.pm @@ -309,10 +309,7 @@ Returns 1 if the object has no children, and 0 otherwise. sub is_leaf { my( $self ) = @_; - my $has_child = $self->result_source->resultset->search( - { $self->_parent_column => $self->id() }, - { limit => 1 } - )->count(); + my $has_child = $self->children_rs->count(); return $has_child ? 0 : 1; }