> So if I understood your suggestion, I would cache the empty resultset > and reuse it on each invocation. > > Nice.
That works because when you do $rs->search/single/etc, copy of $rs is made and returned (and that's why every search/single operation for DBIC is very hard too). Initial $rs remains unchanged. So yo can reuse $class->MyRS infinitely 2010/2/5 Pedro Melo <[email protected]>: > Hi, > > On Fri, Feb 5, 2010 at 2:05 PM, Oleg Pronin <[email protected]> wrote: >> IMHO you are doing the right thing, but i can advice you a futher >> improvement and very important - perfomance boost for your module. >> >> You can do shorcuts shorter: >> in setup_finalize of Catalyst: >> >> foreach my $source ($schema->sources) { >> next unless index($source, '::') == -1; >> my $acc = "${source}RS"; >> $c->mk_group_accessors(inherited => $acc) unless $c->can($acc); >> $c->$acc( scalar $schema->resultset($source) ); >> } >> >> You gain very short accesors (which cannon conflict due to 'RS' suffix) >> for example >> $c->UserRS->single(...) >> $c->ChatMessageRS->search(...) >> >> Plus - such accessors works MUCH MUCH faster than $schema->resultset because >> ->resultset method generates new empty resultset every time and this >> operation is quite hard for DBIC (why???!!!). >> With this accessors all empty resultsets has been already generated on start. > > So if I understood your suggestion, I would cache the empty resultset > and reuse it on each invocation. > > Nice. > > I'll do that for the instance-based code I mentioned yesterday, but I > need to think how to do it properly for the class-based setup that I > have right now. > > As for the code above, it bypasses nested sources. All my sources are > nested. Also the generated SourceRS methods are camel-cased, and I > prefer the lower-case, _-separated that my current code generates. Not > a technical reason, more of an aesthetic one. > > Thanks for the suggestion. > > Bye, > -- > Pedro Melo > http://www.simplicidade.org/ > xmpp:[email protected] > mailto:[email protected] > > _______________________________________________ > List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class > IRC: irc.perl.org#dbix-class > SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ > Searchable Archive: http://www.grokbase.com/group/[email protected] > _______________________________________________ List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ Searchable Archive: http://www.grokbase.com/group/[email protected]
