projects
/
spider.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
increase LRU cache sizes
[spider.git]
/
perl
/
DXUser.pm
diff --git
a/perl/DXUser.pm
b/perl/DXUser.pm
index 84a569497171c9a0cc1584333130e59e8cc321ed..6b85afb3025c4883d247a46b3735f8220cf98d58 100644
(file)
--- a/
perl/DXUser.pm
+++ b/
perl/DXUser.pm
@@
-15,22
+15,24
@@
use Fcntl;
use IO::File;
use DXDebug;
use DXUtil;
use IO::File;
use DXDebug;
use DXUtil;
+use LRU;
use strict;
use vars qw($VERSION $BRANCH);
$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
use strict;
use vars qw($VERSION $BRANCH);
$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
-$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/
) || 0
;
+$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/
|| (0,0))
;
$main::build += $VERSION;
$main::branch += $BRANCH;
$main::build += $VERSION;
$main::branch += $BRANCH;
-use vars qw(%u $dbm $filename %valid $lastoperinterval $lasttime);
+use vars qw(%u $dbm $filename %valid $lastoperinterval $lasttime
$lru $lrusize
);
%u = ();
$dbm = undef;
$filename = undef;
$lastoperinterval = 60*24*60*60;
$lasttime = 0;
%u = ();
$dbm = undef;
$filename = undef;
$lastoperinterval = 60*24*60*60;
$lasttime = 0;
+$lrusize = 2000;
# hash of valid elements and a simple prompt
%valid = (
# hash of valid elements and a simple prompt
%valid = (
@@
-121,6
+123,7
@@
sub init
}
$filename = $fn;
}
$filename = $fn;
+ $lru = LRU->newbase("DXUser", $lrusize);
}
sub del_file
}
sub del_file
@@
-182,8
+185,16
@@
sub get
my $pkg = shift;
my $call = uc shift;
my $data;
my $pkg = shift;
my $call = uc shift;
my $data;
+
+ # is it in the LRU cache?
+ my $ref = $lru->get($call);
+ return $ref if $ref;
+
+ # search for it
unless ($dbm->get($call, $data)) {
unless ($dbm->get($call, $data)) {
- return decode($data);
+ $ref = decode($data);
+ $lru->put($call, $ref);
+ return $ref;
}
return undef;
}
}
return undef;
}
@@
-233,7
+244,9
@@
sub put
$dbm->del($call);
delete $self->{annok} if $self->{annok};
delete $self->{dxok} if $self->{dxok};
$dbm->del($call);
delete $self->{annok} if $self->{annok};
delete $self->{dxok} if $self->{dxok};
- $dbm->put($call, $self->encode);
+ $lru->put($call, $self);
+ my $ref = $self->encode;
+ $dbm->put($call, $ref);
}
#
}
#
@@
-277,6
+290,7
@@
sub del
# for ($dbm->get_dup($call)) {
# $dbm->del_dup($call, $_);
# }
# for ($dbm->get_dup($call)) {
# $dbm->del_dup($call, $_);
# }
+ $lru->remove($call);
$dbm->del($call);
}
$dbm->del($call);
}
@@
-400,8
+414,9
@@
print "There are $count user records and $err errors\n";
for ($action = R_FIRST; !$dbm->seq($key, $val, $action); $action = R_NEXT) {
if (!is_callsign($key) || $key =~ /^0/) {
for ($action = R_FIRST; !$dbm->seq($key, $val, $action); $action = R_NEXT) {
if (!is_callsign($key) || $key =~ /^0/) {
- Log('DXCommand', "Export Error: $key\t$val");
- $dbm->del($key);
+ Log('DXCommand', "Export Error1: $key\t$val");
+ eval {$dbm->del($key)};
+ dbg(carp("Export Error1: $key\t$val\n$@")) if $@;
++$err;
next;
}
++$err;
next;
}
@@
-410,8
+425,9
@@
print "There are $count user records and $err errors\n";
print $fh "$key\t" . $ref->encode . "\n";
++$count;
} else {
print $fh "$key\t" . $ref->encode . "\n";
++$count;
} else {
- Log('DXCommand', "Export Error: $key\t$val");
- $dbm->del($key);
+ Log('DXCommand', "Export Error2: $key\t$val");
+ eval {$dbm->del($key)};
+ dbg(carp("Export Error2: $key\t$val\n$@")) if $@;
++$err;
}
}
++$err;
}
}