Skip to content

Commit

Permalink
Use latest DB.pm from NJH-Snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Oct 7, 2023
1 parent a0e9d29 commit 1faef8a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
17 changes: 15 additions & 2 deletions dynamic-site/lib/Ged2site/DB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ our $directory;
our $logger;
our $cache;

=head1 SUBROUTINES/METHODS
=head2 new
Create an object to point to a read-only database.
Arguments:
cache => place to store results
cache_duration => how long to store results in the cache (default is 1 hour)
=cut

sub new {
my $proto = shift;
my %args = (ref($_[0]) eq 'HASH') ? %{$_[0]} : @_;
Expand Down Expand Up @@ -406,7 +419,7 @@ sub selectall_hash {
push @rc, $href;
}
if($c && wantarray) {
$c->set($key, \@rc, '1 hour');
$c->set($key, \@rc, $self->{'cache_duration'});
}

return @rc;
Expand Down Expand Up @@ -487,7 +500,7 @@ sub fetchrow_hashref {
$sth->execute(@query_args) || throw Error::Simple("$query: @query_args");
if($c) {
my $rc = $sth->fetchrow_hashref();
$c->set($key, $rc, '1 hour');
$c->set($key, $rc, $self->{'cache_duration'});
return $rc;
}
return $sth->fetchrow_hashref();
Expand Down
16 changes: 14 additions & 2 deletions ged2site
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,21 @@ if($opts{'m'} || $opts{'w'}) {

$geocoder->push(Geo::Coder::Free::Local->new());

my %topts;
if(my $oa = $ENV{'OPENADDR_HOME'}) {
$topts{'openaddr'} = $oa;
}
if($logger) {
$topts{'logger'} = $logger;
}
$topts{'cache'} = CHI->new(
driver => 'File',
root_dir => $cachedir,
l1_cache => { driver => 'RawMemory', global => 1, max_size => 1024*1024 }
);
$topts{'cache_duration'} = '1 month';
$freegeocoder = Geo::Coder::Free->new(%topts);
if(my $oa = $ENV{'OPENADDR_HOME'}) {
$freegeocoder = Geo::Coder::Free->new(openaddr => $oa);
# $geocoder->push({ regex => qr/,[\w\s]+,[\w\s]+$/, geocoder => $freegeocoder });
# $geocoder->push({ regex => qr/,\s*(USA|US|United States|Canada|Australia)+$/, geocoder => Geo::Coder::Free::OpenAddresses->new(openaddr => $oa) })
# ->push({ regex => qr/^[\w\s\-]+?,[\w\s]+,[\w\s]+?$/, geocoder => Geo::Coder::Free->new() });
Expand All @@ -584,7 +597,6 @@ if($opts{'m'} || $opts{'w'}) {
$geocoder->push({ regex => qr/,\s*(USA|US|United States|Canada|Australia)\s*$/, geocoder => $freegeocoder })
->push({ regex => qr/^([\w\s]+,)?\s*[\w\s]+,\s*[\w\s]+\s*$/, geocoder => $freegeocoder });
} else {
$freegeocoder = Geo::Coder::Free->new();
$geocoder->push({ regex => qr/^[\w\s\-]+?,[\w\s]+,[\w\s]+?$/, geocoder => $freegeocoder })
# E.g. 'Nebraska, USA'
->push({ regex => qr/^[\w\s]+,\s*(UK|England|Canada|USA|US|United States)$/i, geocoder => $freegeocoder });
Expand Down

0 comments on commit 1faef8a

Please sign in to comment.