| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Logfile::EPrints::Filter::Repeated; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require bytes; |
|
4
|
6
|
|
|
6
|
|
33
|
use Fcntl; |
|
|
6
|
|
|
|
|
10
|
|
|
|
6
|
|
|
|
|
2372
|
|
|
5
|
6
|
|
|
6
|
|
4921
|
use SDBM_File; |
|
|
6
|
|
|
|
|
4272
|
|
|
|
6
|
|
|
|
|
3761
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
48
|
use constant CACHE_TIMEOUT => 60*60*24; # 1 day |
|
|
6
|
|
|
|
|
11
|
|
|
|
6
|
|
|
|
|
432
|
|
|
8
|
6
|
|
|
6
|
|
31
|
use constant REPEATS_CACHE => '/usr/local/share/Logfile/repeatscache.db'; |
|
|
6
|
|
|
|
|
11
|
|
|
|
6
|
|
|
|
|
312
|
|
|
9
|
6
|
|
|
6
|
|
33
|
use vars qw( $AUTOLOAD ); |
|
|
6
|
|
|
|
|
12
|
|
|
|
6
|
|
|
|
|
3257
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new |
|
12
|
|
|
|
|
|
|
{ |
|
13
|
1
|
|
|
1
|
0
|
7
|
my ($class,%args) = @_; |
|
14
|
1
|
|
33
|
|
|
11
|
my $self = bless \%args, ref($class) || $class; |
|
15
|
1
|
|
50
|
|
|
7
|
my $filename = $args{'file'} || REPEATS_CACHE; |
|
16
|
1
|
50
|
|
|
|
2
|
tie %{$self->{cache}}, 'SDBM_File', $filename, O_CREAT|O_RDWR, 0644 |
|
|
1
|
|
|
|
|
146
|
|
|
17
|
|
|
|
|
|
|
or die "Unable to open repeats cache database at $filename: $!"; |
|
18
|
1
|
|
|
|
|
3
|
my @KEYS; |
|
19
|
1
|
|
|
|
|
3
|
while( my ($key, $value) = each %{$self->{cache}} ) |
|
|
1
|
|
|
|
|
32
|
|
|
20
|
|
|
|
|
|
|
{ |
|
21
|
0
|
0
|
|
|
|
0
|
push @KEYS, $key if( $value < time - CACHE_TIMEOUT ); |
|
22
|
|
|
|
|
|
|
} |
|
23
|
1
|
|
|
|
|
5
|
delete $self->{cache}->{$_} for @KEYS; |
|
24
|
1
|
|
|
|
|
12
|
$self; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub DESTROY |
|
28
|
|
|
|
|
|
|
{ |
|
29
|
1
|
|
|
1
|
|
1039
|
untie %{$_[0]->{cache}}; |
|
|
1
|
|
|
|
|
166
|
|
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub AUTOLOAD |
|
33
|
|
|
|
|
|
|
{ |
|
34
|
360
|
50
|
|
360
|
|
857
|
return if $AUTOLOAD =~ /[A-Z]$/; |
|
35
|
360
|
|
|
|
|
1003
|
$AUTOLOAD =~ s/^.*:://; |
|
36
|
360
|
|
|
|
|
1062
|
shift->{handler}->$AUTOLOAD(@_); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub fulltext |
|
40
|
|
|
|
|
|
|
{ |
|
41
|
41
|
|
|
41
|
0
|
43
|
my ($self,$hit) = @_; |
|
42
|
41
|
|
|
|
|
39
|
my $r; |
|
43
|
41
|
|
|
|
|
127
|
my $key = $hit->address . 'x' . $hit->identifier; |
|
44
|
41
|
100
|
66
|
|
|
521
|
if( defined($self->{cache}->{$key}) && |
|
45
|
|
|
|
|
|
|
($hit->utime - $self->{cache}->{$key}) <= CACHE_TIMEOUT |
|
46
|
|
|
|
|
|
|
) { |
|
47
|
9
|
|
|
|
|
1527
|
$r = $self->{handler}->repeated($hit); |
|
48
|
|
|
|
|
|
|
} else { |
|
49
|
32
|
|
|
|
|
105
|
$r = $self->{handler}->fulltext($hit); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
41
|
|
|
|
|
250
|
$self->{cache}->{$key} = $hit->utime; |
|
52
|
41
|
|
|
|
|
7860
|
return $r; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
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 |