summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2010-02-25 20:29:52 -0500
committerEvan Prodromou <evan@status.net>2010-02-25 20:29:52 -0500
commitc693365ae7a27f82afef1765610c41a4bff33726 (patch)
tree2adafa4eb309b6df4c309bcaf332636126a8ed5a
parent1cae324555a7eaddfc7238fd6670351898944c7c (diff)
cache results of webfinger lookups
-rw-r--r--plugins/OStatus/classes/Ostatus_profile.php19
1 files changed, 19 insertions, 0 deletions
diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php
index 8ca28432b..ad9170f5b 100644
--- a/plugins/OStatus/classes/Ostatus_profile.php
+++ b/plugins/OStatus/classes/Ostatus_profile.php
@@ -1338,11 +1338,26 @@ class Ostatus_profile extends Memcached_DataObject
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
$oprofile = Ostatus_profile::staticGet('uri', 'acct:'.$addr);
if (!empty($oprofile)) {
+ self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
return $oprofile;
}
@@ -1353,6 +1368,7 @@ class Ostatus_profile extends Memcached_DataObject
$result = $wf->lookup($addr);
if (!$result) {
+ self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), null);
return null;
}
@@ -1392,6 +1408,7 @@ class Ostatus_profile extends Memcached_DataObject
if (isset($feedUrl)) {
try {
$oprofile = self::ensureProfile($feedUrl, $hints);
+ self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
return $oprofile;
} catch (Exception $e) {
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)) {
try {
$oprofile = self::ensureProfile($profileUrl, $hints);
+ self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
return $oprofile;
} catch (Exception $e) {
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'");
}
+ self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
return $oprofile;
}