in reply to How to cache a regular expression in a DBIx::Class object
I actually thing the InflateColumn approach is best because it will DWIM most of the time. I *think* the only problem in this case is you're purposefully fetching everything on every pass. There's no need-
foreach my $watch_string ( $schema->resultset('WatchString')->all +) # Could be... my $ws = $schema->resultset('WatchString') ->search({}, { cache => 1 }); while( my $line <INPUT> ) { foreach my $watch_string ( $ws->all )
Untested, but as far as I know, it should work. It probably won't be the greatest optimization possible, that would probably involve dispensing with objects and inflating to hashrefs and doing the regex inflation, once, in place in the raw data. That might look like-
my $ws = $schema->resultset('WatchString'); $ws->result_class('DBIx::Class::ResultClass::HashRefInflator'); my @ws = $ws->all; $_->{match_string} = qr/$_->{match_string}/ for @ws; while( my $line <INPUT> ) { foreach my $ws ( @ws ) { if( $line =~ $ws->{match_re} ) # all hashrefs now, no objects. {
I'm less certain of that code but it should be close if not correct.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to cache a regular expression in a DBIx::Class object
by chrestomanci (Priest) on Apr 08, 2011 at 21:19 UTC |