if ($v4) {
my $new = ! -e $ufn;
$dbh = DBI->connect("dbi:SQLite:dbname=$ufn","","") or die "Cannot open $ufn ($!)\n";
- if ($new && $dbh) {
+ if ($new) {
# create the table
my $table = q{create table user(
call text not null unique,
# Add indexes
$dbh->do(q(create index x1 on user(lastseen))) or die $dbh->errstr;
}
+ $dbh->do(q{PRAGMA cache_size = 8000});
+ $dbh->do(q{PRAGMA synchronous = OFF});
}
# is it in the LRU cache?
my $ref = $lru->get($call);
- return $ref if $ref && ref $ref eq 'DXUser';
+ return $ref if $ref && UNIVERSAL::isa($ref, 'DXUser');
# search for it
if ($v4) {
if ($data = _select($call)) {
- $ref = bless decode_json($data), __PACKAGE__;
- $lru->put($call, $ref);
- return $ref;
+ $ref = bless decode_json($data), 'DXUser';
+ unless ($ref) {
+ dbg("DXUser::get: no reference returned from decode of $call $!");
+ return undef;
+ }
}
} else {
unless ($dbm->get($call, $data)) {
$ref = decode($data);
- if ($ref) {
- if (ref $ref ne 'DXUser') {
- dbg("DXUser::get: got strange answer from decode ". ref $ref. " ignoring");
- return undef;
- }
- } else {
- dbg("DXUser::get: no reference returned from decode $!");
+ unless ($ref) {
+ dbg("DXUser::get: no reference returned from decode of $call $!");
return undef;
}
- $lru->put($call, $ref);
- return $ref;
}
}
+ if ($ref) {
+ if (!UNIVERSAL::isa($ref, 'DXUser')) {
+ dbg("DXUser::get: got strange answer from decode of $call". ref $ref. " ignoring");
+ return undef;
+ }
+
+ # we have a reference and it *is* a DXUser
+ $lru->put($call, $ref);
+ return $ref;
+ }
return undef;
}
my $dxchan = DXChannel::get($call);
if ($dxchan) {
my $ref = $dxchan->user;
- return $ref if ref $ref eq 'DXUser';
+ return $ref if $ref && UNIVERSAL::isa($ref, 'DXUser');
- dbg("DXUser::get_current: got invalid user ref from dxchan $dxchan->{call} ". ref $ref. " ignoring");
+ dbg("DXUser::get_current: got invalid user ref for $call from dxchan $dxchan->{call} ". ref $ref. " ignoring");
}
return get($call);
}