[Dbix-class] cache=> 1 and has_many?
George Hartzell
hartzell at alerce.com
Fri Aug 11 18:16:38 CEST 2006
Daniel Westermann-Clark writes:
> [...]
> Since you only want one, you should consider rewriting the grep as a
> database query:
>
> my $apes_1 = $n1->attrs->find({ name => 'APE' });
>
> Or, if name is not unique:
>
> my $apes_1 = $n1->attrs->search({ name => 'APE' })->first;
>
> This is almost certainly more efficient than fetching the full list of
> node attrs from the database.
>
> > Is the cachedness somehow associated with $rn, but not the nodes
> > that I get from ->nodes()?
>
> Right, caching works at the ResultSet level. Any relationship
> accessor on a Row object won't know about the cache.
> [...]
Thanks for the suggestion. I've rewritten those sections as db
queries, and it may be a bit faster, I'll try to actually time it on a
full run at some point. Getting the node_attrs from a node is
actually fairly fast (indexed, etc...) and generally only a handful
come back, so I think that the overhead of doing any database query at
all overwhelms the effect of getting back just the one that I want.
More information about the Dbix-class
mailing list