[Bast-commits] r6844 - in DBIx-Class/0.08/branches/grouped_prefetch: lib/DBIx/Class lib/DBIx/Class/Storage lib/DBIx/Class/Storage/DBI t/prefetch

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Mon Jun 29 10:05:39 GMT 2009


Author: ribasushi
Date: 2009-06-29 10:05:37 +0000 (Mon, 29 Jun 2009)
New Revision: 6844

Modified:
   DBIx-Class/0.08/branches/grouped_prefetch/lib/DBIx/Class/ResultSet.pm
   DBIx-Class/0.08/branches/grouped_prefetch/lib/DBIx/Class/Storage/DBI.pm
   DBIx-Class/0.08/branches/grouped_prefetch/lib/DBIx/Class/Storage/DBI/Cursor.pm
   DBIx-Class/0.08/branches/grouped_prefetch/t/prefetch/grouped.t
Log:
And score! (all works)

Modified: DBIx-Class/0.08/branches/grouped_prefetch/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/branches/grouped_prefetch/lib/DBIx/Class/ResultSet.pm	2009-06-29 09:02:17 UTC (rev 6843)
+++ DBIx-Class/0.08/branches/grouped_prefetch/lib/DBIx/Class/ResultSet.pm	2009-06-29 10:05:37 UTC (rev 6844)
@@ -1312,11 +1312,10 @@
   my @obj;
 
   if (keys %{$self->_resolved_attrs->{collapse}}) {
-#  if ($self->{attrs}{prefetch}) {
-      # Using $self->cursor->all is really just an optimisation.
-      # If we're collapsing has_many prefetches it probably makes
-      # very little difference, and this is cleaner than hacking
-      # _construct_object to survive the approach
+    # Using $self->cursor->all is really just an optimisation.
+    # If we're collapsing has_many prefetches it probably makes
+    # very little difference, and this is cleaner than hacking
+    # _construct_object to survive the approach
     $self->cursor->reset;
     my @row = $self->cursor->next;
     while (@row) {
@@ -1344,6 +1343,8 @@
 =back
 
 Resets the resultset's cursor, so you can iterate through the elements again.
+Implicitly resets the storage cursor, so a subsequent L</next> will trigger
+another query.
 
 =cut
 

Modified: DBIx-Class/0.08/branches/grouped_prefetch/lib/DBIx/Class/Storage/DBI/Cursor.pm
===================================================================
--- DBIx-Class/0.08/branches/grouped_prefetch/lib/DBIx/Class/Storage/DBI/Cursor.pm	2009-06-29 09:02:17 UTC (rev 6843)
+++ DBIx-Class/0.08/branches/grouped_prefetch/lib/DBIx/Class/Storage/DBI/Cursor.pm	2009-06-29 10:05:37 UTC (rev 6844)
@@ -68,7 +68,11 @@
   my ($storage, $dbh, $self) = @_;
 
   $self->_check_dbh_gen;
-  if ($self->{attrs}{rows} && $self->{pos} >= $self->{attrs}{rows}) {
+  if (
+    $self->{attrs}{software_limit}
+      && $self->{attrs}{rows}
+        && $self->{pos} >= $self->{attrs}{rows}
+  ) {
     $self->{sth}->finish if $self->{sth}->{Active};
     delete $self->{sth};
     $self->{done} = 1;
@@ -128,6 +132,7 @@
         && ($self->{attrs}{offset} || $self->{attrs}{rows})) {
     return $self->next::method;
   }
+
   $self->{storage}->dbh_do($self->can('_dbh_all'), $self);
 }
 

Modified: DBIx-Class/0.08/branches/grouped_prefetch/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/branches/grouped_prefetch/lib/DBIx/Class/Storage/DBI.pm	2009-06-29 09:02:17 UTC (rev 6843)
+++ DBIx-Class/0.08/branches/grouped_prefetch/lib/DBIx/Class/Storage/DBI.pm	2009-06-29 10:05:37 UTC (rev 6844)
@@ -1271,7 +1271,6 @@
     ( $attrs->{group_by} && @{$attrs->{group_by}} &&
       $attrs->{prefetch_select} && @{$attrs->{prefetch_select}} )
   ) {
-    $select = [ @$select ]; # it will get mangled
     ($ident, $select, $where, $attrs)
       = $self->_adjust_select_args_for_complex_prefetch ($ident, $select, $where, $attrs);
   }
@@ -1302,7 +1301,12 @@
 sub _adjust_select_args_for_complex_prefetch {
   my ($self, $from, $select, $where, $attrs) = @_;
 
-  $self->throw_exception ('Prefetch with limit (rows/offset) is not supported on resultsets with a custom from attribute')
+  # copies for mangling
+  $from = [ @$from ];
+  $select = [ @$select ];
+  $attrs = { %$attrs };
+
+  $self->throw_exception ('Complex prefetches are not supported on resultsets with a custom from attribute')
     if (ref $from ne 'ARRAY');
 
   # separate attributes
@@ -1337,7 +1341,6 @@
   }
 
   # mangle {from}
-  $from = [ @$from ];
   my $select_root = shift @$from;
   my @outer_from = @$from;
 

Modified: DBIx-Class/0.08/branches/grouped_prefetch/t/prefetch/grouped.t
===================================================================
--- DBIx-Class/0.08/branches/grouped_prefetch/t/prefetch/grouped.t	2009-06-29 09:02:17 UTC (rev 6843)
+++ DBIx-Class/0.08/branches/grouped_prefetch/t/prefetch/grouped.t	2009-06-29 10:05:37 UTC (rev 6844)
@@ -42,6 +42,9 @@
     },
   );
 
+  # this used to fuck up ->all, do not remove!
+  ok ($track_rs->first, 'There is stuff in the rs');
+
   is($track_rs->count, 5, 'Prefetched count with groupby');
   is($track_rs->all, 5, 'Prefetched objects with groupby');
 
@@ -50,14 +53,13 @@
     $schema->storage->debugcb ( sub { $query_cnt++ } );
     $schema->storage->debug (1);
 
-    $track_rs->reset;
     while (my $collapsed_track = $track_rs->next) {
       my $cdid = $collapsed_track->get_column('cd');
       is($collapsed_track->get_column('track_count'), 3, "Correct count of tracks for CD $cdid" );
       ok($collapsed_track->cd->title, "Prefetched title for CD $cdid" );
     }
 
-    is ($query_cnt, 0, 'No queries on prefetched titles');
+    is ($query_cnt, 1, 'Single query on prefetched titles');
     $schema->storage->debugcb (undef);
     $schema->storage->debug ($sdebug);
   }
@@ -180,7 +182,7 @@
 
   is ($most_tracks_rs->count, 2, 'Limit works');
   my $top_cd = $most_tracks_rs->first;
-  is ($top_cd->id, 2, 'Correct cd fetched on top'); # 2 because of the slice(1,1) above
+  is ($top_cd->id, 2, 'Correct cd fetched on top'); # 2 because of the slice(1,1) earlier
 
   my $query_cnt = 0;
   $schema->storage->debugcb ( sub { $query_cnt++ } );




More information about the Bast-commits mailing list