[Bast-commits] r6816 -
DBIx-Class/0.08/branches/search_related_prefetch/lib/DBIx/Class
ribasushi at dev.catalyst.perl.org
ribasushi at dev.catalyst.perl.org
Sun Jun 28 08:35:11 GMT 2009
Author: ribasushi
Date: 2009-06-28 08:35:11 +0000 (Sun, 28 Jun 2009)
New Revision: 6816
Modified:
DBIx-Class/0.08/branches/search_related_prefetch/lib/DBIx/Class/ResultSet.pm
DBIx-Class/0.08/branches/search_related_prefetch/lib/DBIx/Class/ResultSource.pm
Log:
The proposed fix (do not add an extra join if it is already present in the topmost join)
Modified: DBIx-Class/0.08/branches/search_related_prefetch/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/branches/search_related_prefetch/lib/DBIx/Class/ResultSet.pm 2009-06-28 08:34:16 UTC (rev 6815)
+++ DBIx-Class/0.08/branches/search_related_prefetch/lib/DBIx/Class/ResultSet.pm 2009-06-28 08:35:11 UTC (rev 6816)
@@ -2450,7 +2450,7 @@
"' has no such relationship $rel")
unless $rel_info;
- my ($from,$seen) = $self->_resolve_from($rel);
+ my ($from,$seen) = $self->_chain_relationship($rel);
my $join_count = $seen->{$rel};
my $alias = ($join_count > 1 ? join('_', $rel, $join_count) : $rel);
@@ -2548,7 +2548,7 @@
# in order to properly resolve prefetch aliases (any alias
# with a relation_chain_depth less than the depth of the
# current prefetch is not considered)
-sub _resolve_from {
+sub _chain_relationship {
my ($self, $rel) = @_;
my $source = $self->result_source;
my $attrs = $self->{attrs};
@@ -2569,12 +2569,29 @@
# ->_resolve_join as otherwise they get lost - captainL
my $merged = $self->_merge_attr( $attrs->{join}, $attrs->{prefetch} );
- push @$from, $source->_resolve_join($merged, $attrs->{alias}, $seen) if ($merged);
+ my @requested_joins = $source->_resolve_join($merged, $attrs->{alias}, $seen);
+ push @$from, @requested_joins;
+
++$seen->{-relation_chain_depth};
- push @$from, $source->_resolve_join($rel, $attrs->{alias}, $seen);
+ # if $self already had a join/prefetch specified on it, the requested
+ # $rel might very well be already included. What we do in this case
+ # is effectively a no-op (except that we bump up the chain_depth on
+ # the join in question
+ my $already_joined;
+ for my $j (@requested_joins) {
+ if ($rel eq $j->[0]{-join_path}[-1]) {
+ $j->[0]{-relation_chain_depth}++;
+ $already_joined++;
+ last;
+ }
+ }
+ unless ($already_joined) {
+ push @$from, $source->_resolve_join($rel, $attrs->{alias}, $seen);
+ }
+
++$seen->{-relation_chain_depth};
return ($from,$seen);
Modified: DBIx-Class/0.08/branches/search_related_prefetch/lib/DBIx/Class/ResultSource.pm
===================================================================
--- DBIx-Class/0.08/branches/search_related_prefetch/lib/DBIx/Class/ResultSource.pm 2009-06-28 08:34:16 UTC (rev 6815)
+++ DBIx-Class/0.08/branches/search_related_prefetch/lib/DBIx/Class/ResultSource.pm 2009-06-28 08:35:11 UTC (rev 6816)
@@ -893,7 +893,7 @@
}
return unless $f_source; # Can't test rel without f_source
- eval { $self->_resolve_join($rel, 'me') };
+ eval { $self->_resolve_join($rel, 'me', {}) };
if ($@) { # If the resolve failed, back out and re-throw the error
delete $rels{$rel}; #
@@ -1117,6 +1117,8 @@
$self->throw_exception("No idea how to resolve join reftype ".ref $join);
} else {
+ return() unless defined $join;
+
my $count = ++$seen->{$join};
my $as = ($count > 1 ? "${join}_${count}" : $join);
More information about the Bast-commits
mailing list