Skip to content
Snippets Groups Projects
Commit 54b38e53 authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg
Browse files

Add negative caching of IP to geo lookups to speed up feed generation

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2901 44740490-163a-0410-bde0-09ae8108e29a
parent 0777f491
No related branches found
No related tags found
No related merge requests found
...@@ -65,7 +65,9 @@ class sspmod_discojuice_Country { ...@@ -65,7 +65,9 @@ class sspmod_discojuice_Country {
if ($this->store->exists('geo', $ip, NULL)) { if ($this->store->exists('geo', $ip, NULL)) {
SimpleSAML_Logger::debug('IP Geo location (geo): Found ip [' . $ip . '] in cache.'); SimpleSAML_Logger::debug('IP Geo location (geo): Found ip [' . $ip . '] in cache.');
return $this->store->getValue('geo', $ip, NULL); $stored = $this->store->getValue('geo', $ip, NULL);
if ($stored === NULL) throw new Exception('Got negative cache for this IP');
return $stored;
} }
SimpleSAML_Logger::debug('Lookup IP'); SimpleSAML_Logger::debug('Lookup IP');
...@@ -75,6 +77,11 @@ class sspmod_discojuice_Country { ...@@ -75,6 +77,11 @@ class sspmod_discojuice_Country {
$data = json_decode($rawdata, TRUE); $data = json_decode($rawdata, TRUE);
if (empty($data)) throw new Exception('Error decoding response from looking up IP geo location for [' . $ip . ']'); if (empty($data)) throw new Exception('Error decoding response from looking up IP geo location for [' . $ip . ']');
if (empty($data['longitude'])) {
$this->store->set('geo', $ip, NULL, NULL);
}
if (empty($data['longitude'])) throw new Exception('Could not get longitude from IP lookup'); if (empty($data['longitude'])) throw new Exception('Could not get longitude from IP lookup');
if (empty($data['latitude'])) throw new Exception( 'Could not get latitude from IP lookup'); if (empty($data['latitude'])) throw new Exception( 'Could not get latitude from IP lookup');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment