| 1 | package Logfile::EPrints::Filter::Repeated; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 6 | require bytes; | |||||||||||||||||||||||||||
| 4 | 6 | ▶ | use Fcntl; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use SDBM_File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use constant CACHE_TIMEOUT => 60*60*24; # 1 day | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use constant REPEATS_CACHE => '/usr/local/share/Logfile/repeatscache.db'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use vars qw( $AUTOLOAD ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | sub new | ||||||||||||||||||||||||||||
| 12 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=22.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 1 | my ($class,%args) = @_; | |||||||||||||||||||||||||||
| 14 | 1 | ▶ | my $self = bless \%args, ref($class) || $class; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | my $filename = $args{'file'} || REPEATS_CACHE; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{'file'} || '/usr/local/share/Logfile/repeatscache.db'
MC/DC0%0/1
$args{'file'} || '/usr/local/share/Logfile/repeatscache.db'
$args{'file'}
Truth table50%1/2
A
A= $args{'file'}
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | tie %{$self->{cache}}, 'SDBM_File', $filename, O_CREAT|O_RDWR, 0644 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | or die "Unable to open repeats cache database at $filename: $!"; | ||||||||||||||||||||||||||||
| 18 | 1 | my @KEYS; | |||||||||||||||||||||||||||
| 19 | 1 | ▶ | while( my ($key, $value) = each %{$self->{cache}} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | { | ||||||||||||||||||||||||||||
| 21 | 0 | ▶ | push @KEYS, $key if( $value < time - CACHE_TIMEOUT ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | 1 | delete $self->{cache}->{$_} for @KEYS; | |||||||||||||||||||||||||||
| 24 | 1 | $self; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub DESTROY | ||||||||||||||||||||||||||||
| 28 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 1 | untie %{$_[0]->{cache}}; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub AUTOLOAD | ||||||||||||||||||||||||||||
| 33 | 360 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 34 | 360 | ▶ | return if $AUTOLOAD =~ /[A-Z]$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 360 | $AUTOLOAD =~ s/^.*:://; | |||||||||||||||||||||||||||
| 36 | 360 | shift->{handler}->$AUTOLOAD(@_); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | sub fulltext | ||||||||||||||||||||||||||||
| 40 | 41 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
fulltext: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | 41 | my ($self,$hit) = @_; | |||||||||||||||||||||||||||
| 42 | 41 | my $r; | |||||||||||||||||||||||||||
| 43 | 41 | my $key = $hit->address . 'x' . $hit->identifier; | |||||||||||||||||||||||||||
| 44 | 41 | ▶ | if( defined($self->{cache}->{$key}) && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"cache"}{$key} and $hit->utime - $self->{"cache"}{$key} <= 86400
MC/DC50%1/2
defined $self->{"cache"}{$key} and $hit->utime - $self->{"cache"}{$key} <= 86400
defined $self->{"cache"}{$key}
$hit->utime - $self->{"cache"}{$key} <= 86400
Truth table66%2/3
A and B
A= defined $self->{"cache"}{$key}B= $hit->utime - $self->{"cache"}{$key} <= 86400
| |||||||||||||||||||||||||||||
| 45 | ($hit->utime - $self->{cache}->{$key}) <= CACHE_TIMEOUT | ||||||||||||||||||||||||||||
| 46 | ) { | ||||||||||||||||||||||||||||
| 47 | 9 | $r = $self->{handler}->repeated($hit); | |||||||||||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||||||||||
| 49 | 32 | $r = $self->{handler}->fulltext($hit); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 41 | $self->{cache}->{$key} = $hit->utime; | |||||||||||||||||||||||||||
| 52 | 41 | return $r; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 6 | 1; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =pod | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =head1 NAME | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | Logfile::EPrints::Filter::Repeated - Catch fulltext events and check for repeated requests | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | This filter catches fulltext events and either forwards the fulltext event or, if the same identifier has been requested by the same address within 24 hours, create a repeated event. | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =head1 TODO | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | Free memory by removing requests older than 24 hours. | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =head1 HANDLER CALLBACKS | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =over 4 | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =item repeated() | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =back | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||||||||