[Jifty-commit] r5762 - Jifty-DBI/branches/tisql/lib/Jifty/DBI

Jifty commits jifty-commit at lists.jifty.org
Thu Aug 21 00:53:56 EDT 2008


Author: ruz
Date: Thu Aug 21 00:53:54 2008
New Revision: 5762

Modified:
   Jifty-DBI/branches/tisql/lib/Jifty/DBI/Collection.pm
   Jifty-DBI/branches/tisql/lib/Jifty/DBI/Handle.pm

Log:
* reimplement depends_on, joins optimisation is turned off however

Modified: Jifty-DBI/branches/tisql/lib/Jifty/DBI/Collection.pm
==============================================================================
--- Jifty-DBI/branches/tisql/lib/Jifty/DBI/Collection.pm	(original)
+++ Jifty-DBI/branches/tisql/lib/Jifty/DBI/Collection.pm	Thu Aug 21 00:53:54 2008
@@ -1332,6 +1332,20 @@
         }
     }
 
+    if ( $args{'leftjoin'} && $args{'alias'} ne $args{'leftjoin'} ) {
+        my $deps = $self->{'joins'}{ $args{'leftjoin'} }{'depends_on'};
+        unless ( grep $_ eq $args{'alias'}, @$deps ) {
+            push @$deps, $args{'alias'};
+        }
+    }
+    if ( $args{'leftjoin'} && !$args{'quote_value'} && ($args{'value'}||'') =~ /^(\w+)\./ ) {
+        my $alias = $1;
+        my $deps = $self->{'joins'}{ $args{'leftjoin'} }{'depends_on'};
+        if ( $alias ne $args{'leftjoin'} && !grep $_ eq $alias, @$deps ) {
+            push @$deps, $alias;
+        }
+    }
+
     if ( $value_ref eq 'ARRAY' ) {
         croak
             'Limits with an array ref are only allowed with operator \'IN\' or \'=\''
@@ -1775,7 +1789,7 @@
         type  => $type,
         ( $class ? ( class => $class ) : () ),
         alias_string => " $type JOIN $table $alias ",
-        depends_on => 'main',
+        depends_on => [],
     };
 
     return $alias;

Modified: Jifty-DBI/branches/tisql/lib/Jifty/DBI/Handle.pm
==============================================================================
--- Jifty-DBI/branches/tisql/lib/Jifty/DBI/Handle.pm	(original)
+++ Jifty-DBI/branches/tisql/lib/Jifty/DBI/Handle.pm	Thu Aug 21 00:53:54 2008
@@ -966,7 +966,7 @@
         $meta->{'alias_string'} = " JOIN " . $args{'table2'} . " $alias ";
         $meta->{'type'}         = 'NORMAL';
     }
-    $meta->{'depends_on'}       = $args{'alias1'};
+    $meta->{'depends_on'}       = [ $args{'alias1'} ];
     $meta->{'is_distinct'}      = $args{'is_distinct'};
     $meta->{'class'}            = $args{'class2'} if $args{'class2'};
     $meta->{'entry_aggregator'} = $args{'entry_aggregator'}
@@ -990,7 +990,7 @@
     my $self       = shift;
     my $collection = shift;
 
-    $self->_optimize_joins( collection => $collection );
+    #$self->_optimize_joins( collection => $collection );
 
     my @cross = grep { lc $_->{type} eq "cross" }
         values %{ $collection->{'joins'} };
@@ -1005,12 +1005,15 @@
     my %processed = map { $_->{alias} => 1 } @cross;
     $processed{'main'} = 1;
 
-# get a @list of joins that have not been processed yet, but depend on processed join
     my $joins = $collection->{'joins'};
-    while ( my @list = grep !$processed{$_}
-        && $processed{ $joins->{$_}{'depends_on'} }, keys %$joins )
-    {
+    while ( my @list = grep !$processed{$_}, keys %$joins ) {
+        # if all not yet processed joins have unsatisfied dependencies then
+        # we should barf
+        my $joined_at_least_one = 0;
         foreach my $join (@list) {
+            my $deps = $joins->{$join}{'depends_on'};
+            next if grep !$processed{$_}, @$deps;
+
             $processed{$join}++;
 
             my $meta = $joins->{$join};
@@ -1031,7 +1034,9 @@
             # delete last aggregator
             pop @tmp;
             $join_clause .= CORE::join ' ', @tmp;
+            $joined_at_least_one++
         }
+        last unless $joined_at_least_one;
     }
 
 # here we could check if there is recursion in joins by checking that all joins


More information about the Jifty-commit mailing list