diff options
author | Zarino Zappia <mail@zarino.co.uk> | 2020-02-25 14:59:49 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2020-02-26 13:52:14 +0000 |
commit | a8de040b29e18a9bf916e65a12b293b708b9f5cd (patch) | |
tree | 5caefadab8b17c5f29dda5bffbc95e8830638414 /perllib/FixMyStreet/App/Controller | |
parent | a6b58401b3bef860713f96c1ba5c576bd94e0b10 (diff) |
Optional logging of unsuccessful location searches
If a SQLite file exists at `../data/analytics.sqlite` with a table
named `location_searches_with_no_results`, then a row will be created
for each /around search that returns no results.
Could come in useful for anybody running an instance and looking to
better understand how well their geocoder is performing.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Location.pm | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Location.pm b/perllib/FixMyStreet/App/Controller/Location.pm index 8d5b0b147..81c2c33fc 100644 --- a/perllib/FixMyStreet/App/Controller/Location.pm +++ b/perllib/FixMyStreet/App/Controller/Location.pm @@ -6,6 +6,7 @@ BEGIN {extends 'Catalyst::Controller'; } use Encode; use FixMyStreet::Geocode; +use Try::Tiny; use Utils; =head1 NAME @@ -107,6 +108,25 @@ sub determine_location_from_pc : Private { # pass errors back to the template $c->stash->{location_error_pc_lookup} = 1; $c->stash->{location_error} = $error; + + # Log failure in a log db + try { + my $dbfile = FixMyStreet->path_to('../data/analytics.sqlite'); + my $db = DBI->connect("dbi:SQLite:dbname=$dbfile", undef, undef) or die "$DBI::errstr\n"; + my $sth = $db->prepare("INSERT INTO location_searches_with_no_results + (datetime, cobrand, geocoder, url, user_input) + VALUES (?, ?, ?, ?, ?)") or die $db->errstr . "\n"; + my $rv = $sth->execute( + POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime(time())), + $c->cobrand->moniker, + $c->cobrand->get_geocoder(), + $c->stash->{geocoder_url}, + $pc, + ); + } catch { + $c->log->debug("Unable to log to analytics.sqlite: $_"); + }; + return; } |