[Dbix-class] DBIC hits DB thoguh using prefetch (repost)
Moritz Onken
onken at houseofdesign.de
Sun Jul 27 08:07:41 BST 2008
>>
>
> Hi Moritz,
>
> Nope, you're misunderstanding how it works.
>
> Search with prefetch fetches data and stores it in the resultset
> when next/all are called on the resultset.
>
> However find() doesnt use prefetched data at all, there is no
> caching for find.
>
> $rs->first, doesnt run any extra queries. Since that's now not part
> of the resultset any more, any rels called on the result of first()
> also produce more queries.
>
> In short, it only works on chained resultset objects.
>
> Jess
>
Thanks, that makes sense. But I recognized that the test case didn't
exactly show
where my problem is. I edited the test:
my @rs =
$schema->resultset("Complex")
->search( undef, { prefetch => { parents => "parent" } } );
for (@rs) {
is( defined $_->parents->first->parent->id, 1 );
}
So now I'm not using find, but it still hits the database for every row.
New test is attached.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test4list.tgz
Type: application/octet-stream
Size: 1636 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20080727/65444ce6/test4list.obj
More information about the DBIx-Class
mailing list