X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fprefetch%2Fvia_search_related.t;h=f1aa3d00065b7d312ca5e1d7d781228914a1896d;hb=49eeb48de3d8ff685926b595fa0f3f5e680eaee2;hp=588b125051776f12cf5f55a15e04ee3ca182976a;hpb=2cfc22ddff9cb35524031dfc9d429d294b5e3d6e;p=dbsrgits%2FDBIx-Class.git diff --git a/t/prefetch/via_search_related.t b/t/prefetch/via_search_related.t index 588b125..f1aa3d0 100644 --- a/t/prefetch/via_search_related.t +++ b/t/prefetch/via_search_related.t @@ -9,10 +9,6 @@ use DBICTest; my $schema = DBICTest->init_schema(); -my $queries; -my $debugcb = sub { $queries++; }; -my $orig_debug = $schema->storage->debug; - lives_ok ( sub { my $no_prefetch = $schema->resultset('Track')->search_related(cd => { @@ -73,16 +69,12 @@ lives_ok ( sub { { my $cd = $schema->resultset('CD')->search({}, { prefetch => 'cd_to_producer' })->find(1); - $queries = 0; - $schema->storage->debugcb ($debugcb); - $schema->storage->debug (1); - - is( $cd->cd_to_producer->count, 3 ,'Count of prefetched m2m links via accessor' ); - is( scalar $cd->cd_to_producer->all, 3, 'Amount of prefetched m2m link objects via accessor' ); - is( $cd->search_related('cd_to_producer')->count, 3, 'Count of prefetched m2m links via search_related' ); - is( scalar $cd->search_related('cd_to_producer')->all, 3, 'Amount of prefetched m2m links via search_related' ); - - is($queries, 0, 'No queries ran so far'); + $schema->is_executed_querycount( sub { + is( $cd->cd_to_producer->count, 3 ,'Count of prefetched m2m links via accessor' ); + is( scalar $cd->cd_to_producer->all, 3, 'Amount of prefetched m2m link objects via accessor' ); + is( $cd->search_related('cd_to_producer')->count, 3, 'Count of prefetched m2m links via search_related' ); + is( scalar $cd->search_related('cd_to_producer')->all, 3, 'Amount of prefetched m2m links via search_related' ); + }, 0, 'No queries ran so far'); is( scalar $cd->cd_to_producer->search_related('producer')->all, 3, 'Amount of objects via search_related off prefetched linker' ); @@ -97,16 +89,12 @@ lives_ok ( sub { is( $cd->producers->count, 3, 'Count via m2m accessor' ); - $queries = 0; - - is( $cd->cd_to_producer->count, 3 ,'Review count of prefetched m2m links via accessor' ); - is( scalar $cd->cd_to_producer->all, 3, 'Review amount of prefetched m2m link objects via accessor' ); - is( $cd->search_related('cd_to_producer')->count, 3, 'Review count of prefetched m2m links via search_related' ); - is( scalar $cd->search_related('cd_to_producer')->all, 3, 'Rreview amount of prefetched m2m links via search_related' ); - - is($queries, 0, 'Still no queries on prefetched linker'); - $schema->storage->debugcb (undef); - $schema->storage->debug ($orig_debug); + $schema->is_executed_querycount( sub { + is( $cd->cd_to_producer->count, 3 ,'Review count of prefetched m2m links via accessor' ); + is( scalar $cd->cd_to_producer->all, 3, 'Review amount of prefetched m2m link objects via accessor' ); + is( $cd->search_related('cd_to_producer')->count, 3, 'Review count of prefetched m2m links via search_related' ); + is( scalar $cd->search_related('cd_to_producer')->all, 3, 'Rreview amount of prefetched m2m links via search_related' ); + }, 0, 'Still no queries on prefetched linker'); } # tests with distinct => 1 @@ -169,21 +157,18 @@ lives_ok (sub { is($rs->all, 1, 'distinct with prefetch (objects)'); is($rs->count, 1, 'distinct with prefetch (count)'); - $queries = 0; - $schema->storage->debugcb ($debugcb); - $schema->storage->debug (1); + local $TODO = "This makes another 2 trips to the database, it can't be right"; + $schema->is_executed_querycount( sub { - # artist -> 2 cds -> 2 genres -> 2 cds for each genre + distinct = 2 - is($rs->search_related('cds')->all, 2, 'prefetched distinct with prefetch (objects)'); - is($rs->search_related('cds')->count, 2, 'prefetched distinct with prefetch (count)'); + # the is() calls are not todoified + local $TODO; - { - local $TODO = "This makes another 2 trips to the database, it can't be right"; - is ($queries, 0, 'No extra queries fired (prefetch survives search_related)'); - } + # artist -> 2 cds -> 2 genres -> 2 cds for each genre + distinct = 2 + is($rs->search_related('cds')->all, 2, 'prefetched distinct with prefetch (objects)'); + is($rs->search_related('cds')->count, 2, 'prefetched distinct with prefetch (count)'); + + }, 0, 'No extra queries fired (prefetch survives search_related)'); - $schema->storage->debugcb (undef); - $schema->storage->debug ($orig_debug); }, 'distinct generally works with prefetch on deep search_related chains'); # pathological "user knows what they're doing" case