cache results of webfinger lookups

This commit is contained in:
Evan Prodromou 2010-02-25 20:29:52 -05:00
parent 1cae324555
commit c693365ae7

View File

@ -1338,11 +1338,26 @@ class Ostatus_profile extends Memcached_DataObject
public static function ensureWebfinger($addr) public static function ensureWebfinger($addr)
{ {
// First, try the cache
$uri = self::cacheGet(sprintf('ostatus_profile:webfinger:%s', $addr));
if ($uri !== false) {
if (is_null($uri)) {
return null;
}
$oprofile = Ostatus_profile::staticGet('uri', $uri);
if (!empty($oprofile)) {
return $oprofile;
}
}
// First, look it up // First, look it up
$oprofile = Ostatus_profile::staticGet('uri', 'acct:'.$addr); $oprofile = Ostatus_profile::staticGet('uri', 'acct:'.$addr);
if (!empty($oprofile)) { if (!empty($oprofile)) {
self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
return $oprofile; return $oprofile;
} }
@ -1353,6 +1368,7 @@ class Ostatus_profile extends Memcached_DataObject
$result = $wf->lookup($addr); $result = $wf->lookup($addr);
if (!$result) { if (!$result) {
self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), null);
return null; return null;
} }
@ -1392,6 +1408,7 @@ class Ostatus_profile extends Memcached_DataObject
if (isset($feedUrl)) { if (isset($feedUrl)) {
try { try {
$oprofile = self::ensureProfile($feedUrl, $hints); $oprofile = self::ensureProfile($feedUrl, $hints);
self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
return $oprofile; return $oprofile;
} catch (Exception $e) { } catch (Exception $e) {
common_log(LOG_WARNING, "Failed creating profile from feed URL '$feedUrl': " . $e->getMessage()); common_log(LOG_WARNING, "Failed creating profile from feed URL '$feedUrl': " . $e->getMessage());
@ -1404,6 +1421,7 @@ class Ostatus_profile extends Memcached_DataObject
if (isset($profileUrl)) { if (isset($profileUrl)) {
try { try {
$oprofile = self::ensureProfile($profileUrl, $hints); $oprofile = self::ensureProfile($profileUrl, $hints);
self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
return $oprofile; return $oprofile;
} catch (Exception $e) { } catch (Exception $e) {
common_log(LOG_WARNING, "Failed creating profile from profile URL '$profileUrl': " . $e->getMessage()); common_log(LOG_WARNING, "Failed creating profile from profile URL '$profileUrl': " . $e->getMessage());
@ -1455,6 +1473,7 @@ class Ostatus_profile extends Memcached_DataObject
throw new Exception("Couldn't save ostatus_profile for '$addr'"); throw new Exception("Couldn't save ostatus_profile for '$addr'");
} }
self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
return $oprofile; return $oprofile;
} }