From: Peter Rabbitson Date: Mon, 29 Jun 2009 10:05:37 +0000 (+0000) Subject: And score! (all works) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=22ed9526e0504bbfbd6b288302160224f50e58f0;p=dbsrgits%2FDBIx-Class-Historic.git And score! (all works) --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 5e82fb4..217e1c8 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1312,11 +1312,10 @@ sub all { 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 @@ sub all { =back Resets the resultset's cursor, so you can iterate through the elements again. +Implicitly resets the storage cursor, so a subsequent L will trigger +another query. =cut diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index bf5c824..cd75e9c 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1271,7 +1271,6 @@ sub _select_args { ( $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 _select_args { 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 @@ sub _adjust_select_args_for_complex_prefetch { } # mangle {from} - $from = [ @$from ]; my $select_root = shift @$from; my @outer_from = @$from; diff --git a/lib/DBIx/Class/Storage/DBI/Cursor.pm b/lib/DBIx/Class/Storage/DBI/Cursor.pm index bd2a20a..2868f88 100644 --- a/lib/DBIx/Class/Storage/DBI/Cursor.pm +++ b/lib/DBIx/Class/Storage/DBI/Cursor.pm @@ -68,7 +68,11 @@ sub _dbh_next { 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 @@ sub all { && ($self->{attrs}{offset} || $self->{attrs}{rows})) { return $self->next::method; } + $self->{storage}->dbh_do($self->can('_dbh_all'), $self); } diff --git a/t/prefetch/grouped.t b/t/prefetch/grouped.t index b44d701..85fd730 100644 --- a/t/prefetch/grouped.t +++ b/t/prefetch/grouped.t @@ -42,6 +42,9 @@ for ($cd_rs->all) { }, ); + # 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 @@ for ($cd_rs->all) { $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 @@ for ($cd_rs->all) { 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++ } );