[Bast-commits] r3383 - in branches/DBIx-Class-current: lib/DBIx/Class t

matthewt at dev.catalyst.perl.org matthewt at dev.catalyst.perl.org
Fri May 25 17:00:52 GMT 2007


Author: matthewt
Date: 2007-05-25 17:00:52 +0100 (Fri, 25 May 2007)
New Revision: 3383

Modified:
   branches/DBIx-Class-current/lib/DBIx/Class/ResultSet.pm
   branches/DBIx-Class-current/lib/DBIx/Class/Row.pm
   branches/DBIx-Class-current/t/76joins.t
Log:
prefetch/cache fixes for all but find

Modified: branches/DBIx-Class-current/lib/DBIx/Class/ResultSet.pm
===================================================================
--- branches/DBIx-Class-current/lib/DBIx/Class/ResultSet.pm	2007-05-25 15:14:08 UTC (rev 3382)
+++ branches/DBIx-Class-current/lib/DBIx/Class/ResultSet.pm	2007-05-25 16:00:52 UTC (rev 3383)
@@ -1622,18 +1622,32 @@
     my %attrs = %{$self->{attrs}||{}};
     delete $attrs{result_class};
 
-    $self->_source_handle->schema->resultset($rel_obj->{class})->search_rs(
-      undef, {
-        %attrs,
-        join => undef,
-        prefetch => undef,
-        select => undef,
-        as => undef,
-        alias => $alias,
-        where => $self->{cond},
-        seen_join => $seen,
-        from => $from,
-    });
+    my $new_cache;
+
+    if (my $cache = $self->get_cache) {
+      if ($cache->[0] && $cache->[0]->related_resultset($rel)->get_cache) {
+        $new_cache = [ map { @{$_->related_resultset($rel)->get_cache} }
+                        @$cache ];
+      }
+    }
+
+    my $new = $self->_source_handle
+                   ->schema
+                   ->resultset($rel_obj->{class})
+                   ->search_rs(
+                       undef, {
+                         %attrs,
+                         join => undef,
+                         prefetch => undef,
+                         select => undef,
+                         as => undef,
+                         alias => $alias,
+                         where => $self->{cond},
+                         seen_join => $seen,
+                         from => $from,
+                     });
+    $new->set_cache($new_cache) if $new_cache;
+    $new;
   };
 }
 

Modified: branches/DBIx-Class-current/lib/DBIx/Class/Row.pm
===================================================================
--- branches/DBIx-Class-current/lib/DBIx/Class/Row.pm	2007-05-25 15:14:08 UTC (rev 3382)
+++ branches/DBIx-Class-current/lib/DBIx/Class/Row.pm	2007-05-25 16:00:52 UTC (rev 3383)
@@ -448,6 +448,7 @@
         $fetched = $pre_source->result_class->inflate_result(
                       $pre_source, @{$pre_val});
       }
+      $new->related_resultset($pre)->set_cache([ $fetched ]);
       my $accessor = $source->relationship_info($pre)->{attrs}{accessor};
       $class->throw_exception("No accessor for prefetched $pre")
        unless defined $accessor;

Modified: branches/DBIx-Class-current/t/76joins.t
===================================================================
--- branches/DBIx-Class-current/t/76joins.t	2007-05-25 15:14:08 UTC (rev 3382)
+++ branches/DBIx-Class-current/t/76joins.t	2007-05-25 16:00:52 UTC (rev 3383)
@@ -169,7 +169,7 @@
 cmp_ok($rs + 0, '==', 3, 'Correct number of records returned');
 
 my $queries = 0;
-$schema->storage->debugcb(sub { $queries++ });
+$schema->storage->debugcb(sub { $queries++; });
 $schema->storage->debug(1);
 
 my @cd = $rs->all;
@@ -226,12 +226,8 @@
    'Caterwauler McCrae',
    'chained belongs_to->belongs_to search_related ok');
 
-TODO: {
-  local $TODO = 'use prefetched values for nested search_related';
+is($queries, 0, 'chained search_related after belontgs_to->belongs_to prefetch ran no queries');
 
-  is($queries, 0, 'chained search_related after belontgs_to->belongs_to prefetch ran no queries');
-}
-
 $queries = 0;
 
 $cd = $schema->resultset('CD')->find(1, { prefetch => 'artist' });
@@ -242,6 +238,8 @@
 
 $queries = 0;
 
+$schema->storage->debugcb(sub { $queries++; warn "Q: @_"; });
+
 $cd = $schema->resultset('CD')->find(1, { prefetch => { cd_to_producer => 'producer' } });
 
 is($cd->producers->first->name, 'Matt S Trout', 'many_to_many accessor ok');
@@ -258,12 +256,8 @@
 
 is($producers->first->name, 'Matt S Trout', 'chained many_to_many search_related ok');
 
-TODO: {
-  local $TODO = 'use prefetched values for search_related';
+is($queries, 0, 'chained search_related after many_to_many prefetch ran no queries');
 
-  is($queries, 0, 'chained search_related after many_to_many prefetch ran no queries');
-}
-
 $schema->storage->debug($orig_debug);
 $schema->storage->debugobj->callback(undef);
 
@@ -416,7 +410,8 @@
     {},
     {
         join     => [ { cds => ['tracks'] } ],
-        prefetch => [ { cds => ['tracks'] } ]
+        prefetch => [ { cds => ['tracks'] } ],
+        cache    => 1 # last test needs this
     }
 );
 
@@ -461,8 +456,4 @@
    'chained has_many->has_many search_related ok'
   );
 
-TODO: {
-  local $TODO ='use prefetched values for chained search_related';
-
-  is($queries, 0, 'chained search_related after has_many->has_many prefetch ran no queries');
-}
+is($queries, 0, 'chained search_related after has_many->has_many prefetch ran no queries');




More information about the Bast-commits mailing list