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.

>From the docs, it looks like this:

  $na_rs = $rn->nodes()->search();

will give me a result set that I can iterate over.  Can I do something
like this:

  $na_rs = $rn->nodes()->search(undef, {cache => 1});

and then 

  grep {...} @{$na_rs->all()}

or something.

Although at that point I could just do:

  @foo = $rn->nodes();

and then run my greps over @foo....

The real answer to my problem is probably figuring out how to make
prefetch do what I need, which is a conversation that we're already
having in another thread.

Thanks,

g.

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to