From: Matt S Trout Date: Sun, 20 Jan 2008 12:28:55 +0000 (+0000) Subject: made search_rs smarter about when to preserve the cache to fix mm prefetch usage X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0ed8d3b659c714c617fa211f32f34879c5b224f0;p=dbsrgits%2FDBIx-Class-Historic.git made search_rs smarter about when to preserve the cache to fix mm prefetch usage --- diff --git a/Changes b/Changes index 3832053..870de96 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for DBIx::Class + - Made search_rs smarter about when to preserve the cache to fix + mm prefetch usage - Added Storage::DBI subclass for MSSQL over ODBC. - Added freeze, thaw and dclone methods to Schema so that thawed objects will get re-attached to the schema. diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 25d8b03..c2b045c 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -11,6 +11,7 @@ use Data::Page; use Storable; use DBIx::Class::ResultSetColumn; use DBIx::Class::ResultSourceHandle; +use List::Util (); use base qw/DBIx::Class/; __PACKAGE__->mk_group_accessors('simple' => qw/result_class _source_handle/); @@ -168,18 +169,26 @@ always return a resultset, even in list context. sub search_rs { my $self = shift; - my $rows; - - unless (@_) { # no search, effectively just a clone - $rows = $self->get_cache; - } - my $attrs = {}; $attrs = pop(@_) if @_ > 1 and ref $_[$#_] eq 'HASH'; my $our_attrs = { %{$self->{attrs}} }; my $having = delete $our_attrs->{having}; my $where = delete $our_attrs->{where}; + my $rows; + + my %safe = (alias => 1, cache => 1); + + unless ( + (@_ && defined($_[0])) # @_ == () or (undef) + || + (keys %$attrs # empty attrs or only 'safe' attrs + && List::Util::first { !$safe{$_} } keys %$attrs) + ) { + # no search, effectively just a clone + $rows = $self->get_cache; + } + my $new_attrs = { %{$our_attrs}, %{$attrs} }; # merge new attrs into inherited diff --git a/t/76joins.t b/t/76joins.t index 92e5785..101d71f 100644 --- a/t/76joins.t +++ b/t/76joins.t @@ -247,11 +247,7 @@ $cd = $schema->resultset('CD')->find(1, { prefetch => { cd_to_producer => 'produ is($cd->producers->first->name, 'Matt S Trout', 'many_to_many accessor ok'); -TODO: { - local $TODO = 'use prefetched values for many_to_many accessor'; - - is($queries, 1, 'many_to_many accessor with nested prefetch ran exactly 1 query'); -} +is($queries, 1, 'many_to_many accessor with nested prefetch ran exactly 1 query'); $queries = 0;