- for ($i = $count = 0; $i < $maxdays; ++$i) { # look thru $maxdays worth of files only
- my $now = $fromdate->sub($i); # but you can pick which $maxdays worth
- last if $now->cmp($todate) <= 0;
-
- my @spots = ();
- my $fh = $fp->open($now); # get the next file
- if ($fh) {
- my $in;
- eval $eval; # do the search on this file
- last if $count >= $to; # stop after to
- return ("Spot search error", $@) if $@;
+ my $this = $now->sub($i);
+ my $fn = $fp->fn($this);
+ my $cachekey = _cachek($this);
+ my $rec = 0;
+
+ if ($spotcachedays > 0 && $spotcache{$cachekey}) {
+ foreach my $r (@{$spotcache{$cachekey}}) {
+ ++$rec;
+ if ($dofilter && $dxchan && $dxchan->{spotsfilter}) {
+ my ($gotone, undef) = $dxchan->{spotsfilter}->it(@$r);
+ next unless $gotone;
+ }
+ if (&$ecode($r)) {
+ ++$count;
+ next if $count < $from;
+ push @out, $r;
+ last if $count >= $to;
+ }
+ }
+ dbg("Spot::search cache recs read: $rec") if isdbg('search');
+ } else {
+ if ($readback) {
+ dbg("Spot::search search using tac fn: $fn $i") if isdbg('search');
+ $fh = IO::File->new("$readback $fn |");
+ }
+ else {
+ dbg("Spot::search search fn: $fp->{fn} $i") if isdbg('search');
+ $fh = $fp->open($now->sub($i)); # get the next file
+ }
+ if ($fh) {
+ my $in;
+ while (<$fh>) {
+ chomp;
+ my @r = split /\^/;
+ ++$rec;
+ if ($dofilter && $dxchan && $dxchan->{spotsfilter}) {
+ my ($gotone, undef) = $dxchan->{spotsfilter}->it(@r);
+ next unless $gotone;
+ }
+ if (&$ecode(\@r)) {
+ ++$count;
+ next if $count < $from;
+ if ($readback) {
+ push @out, \@r;
+ last if $count >= $to;
+ } else {
+ push @out, \@r;
+ shift @out if $count >= $to;
+ }
+ }
+ }
+ dbg("Spot::search file recs read: $rec") if isdbg('search');
+ last if $count >= $to; # stop after to
+ }