OStatus: clean up known-URL hinting during profile setup, saves some extra HTTP hits we were getting when mentioning Buzz feeds.

This commit is contained in:
Brion Vibber 2010-02-25 19:48:28 -08:00
parent 2fa953da22
commit 2528bb452b

@ -791,11 +791,18 @@ class Ostatus_profile extends Memcached_DataObject
{ {
// Get the canonical feed URI and check it // Get the canonical feed URI and check it
$discover = new FeedDiscovery(); $discover = new FeedDiscovery();
$feeduri = $discover->discoverFromURL($profile_uri); if ($hints['feedurl']) {
$feeduri = $hints['feedurl'];
$feeduri = $discover->discoverFromFeedURL($feeduri);
} else {
$feeduri = $discover->discoverFromURL($profile_uri);
$hints['feedurl'] = $feeduri;
}
//$feedsub = FeedSub::ensureFeed($feeduri, $discover->feed);
$huburi = $discover->getAtomLink('hub'); $huburi = $discover->getAtomLink('hub');
$hints['hub'] = $huburi;
$salmonuri = $discover->getAtomLink('salmon'); $salmonuri = $discover->getAtomLink('salmon');
$hints['salmon'] = $salmonuri;
if (!$huburi) { if (!$huburi) {
// We can only deal with folks with a PuSH hub // We can only deal with folks with a PuSH hub
@ -810,7 +817,7 @@ class Ostatus_profile extends Memcached_DataObject
if (!empty($subject)) { if (!empty($subject)) {
$subjObject = new ActivityObject($subject); $subjObject = new ActivityObject($subject);
return self::ensureActivityObjectProfile($subjObject, $feeduri, $salmonuri, $hints); return self::ensureActivityObjectProfile($subjObject, $hints);
} }
// Otherwise, try the feed author // Otherwise, try the feed author
@ -819,7 +826,7 @@ class Ostatus_profile extends Memcached_DataObject
if (!empty($author)) { if (!empty($author)) {
$authorObject = new ActivityObject($author); $authorObject = new ActivityObject($author);
return self::ensureActivityObjectProfile($authorObject, $feeduri, $salmonuri, $hints); return self::ensureActivityObjectProfile($authorObject, $hints);
} }
// Sheesh. Not a very nice feed! Let's try fingerpoken in the // Sheesh. Not a very nice feed! Let's try fingerpoken in the
@ -835,7 +842,7 @@ class Ostatus_profile extends Memcached_DataObject
if (!empty($actor)) { if (!empty($actor)) {
$actorObject = new ActivityObject($actor); $actorObject = new ActivityObject($actor);
return self::ensureActivityObjectProfile($actorObject, $feeduri, $salmonuri, $hints); return self::ensureActivityObjectProfile($actorObject, $hints);
} }
@ -843,7 +850,7 @@ class Ostatus_profile extends Memcached_DataObject
if (!empty($author)) { if (!empty($author)) {
$authorObject = new ActivityObject($author); $authorObject = new ActivityObject($author);
return self::ensureActivityObjectProfile($authorObject, $feeduri, $salmonuri, $hints); return self::ensureActivityObjectProfile($authorObject, $hints);
} }
} }
@ -988,18 +995,18 @@ class Ostatus_profile extends Memcached_DataObject
* @return Ostatus_profile * @return Ostatus_profile
*/ */
public static function ensureActorProfile($activity, $feeduri=null, $salmonuri=null) public static function ensureActorProfile($activity, $hints=array())
{ {
return self::ensureActivityObjectProfile($activity->actor, $feeduri, $salmonuri); return self::ensureActivityObjectProfile($activity->actor, $hints);
} }
public static function ensureActivityObjectProfile($object, $feeduri=null, $salmonuri=null, $hints=array()) public static function ensureActivityObjectProfile($object, $hints=array())
{ {
$profile = self::getActivityObjectProfile($object); $profile = self::getActivityObjectProfile($object);
if ($profile) { if ($profile) {
$profile->updateFromActivityObject($object, $hints); $profile->updateFromActivityObject($object, $hints);
} else { } else {
$profile = self::createActivityObjectProfile($object, $feeduri, $salmonuri, $hints); $profile = self::createActivityObjectProfile($object, $hints);
} }
return $profile; return $profile;
} }
@ -1045,58 +1052,55 @@ class Ostatus_profile extends Memcached_DataObject
* @fixme validate stuff somewhere * @fixme validate stuff somewhere
*/ */
protected static function createActorProfile($activity, $feeduri=null, $salmonuri=null)
{
$actor = $activity->actor;
self::createActivityObjectProfile($actor, $feeduri, $salmonuri);
}
/** /**
* Create local ostatus_profile and profile/user_group entries for * Create local ostatus_profile and profile/user_group entries for
* the provided remote user or group. * the provided remote user or group.
* *
* @param ActivityObject $object * @param ActivityObject $object
* @param string $feeduri
* @param string $salmonuri
* @param array $hints * @param array $hints
* *
* @fixme fold $feeduri/$salmonuri into $hints
* @return Ostatus_profile * @return Ostatus_profile
*/ */
protected static function createActivityObjectProfile($object, $feeduri=null, $salmonuri=null, $hints=array()) protected static function createActivityObjectProfile($object, $hints=array())
{ {
$homeuri = $object->id; $homeuri = $object->id;
$discover = false;
if (!$homeuri) { if (!$homeuri) {
common_log(LOG_DEBUG, __METHOD__ . " empty actor profile URI: " . var_export($activity, true)); common_log(LOG_DEBUG, __METHOD__ . " empty actor profile URI: " . var_export($activity, true));
throw new ServerException("No profile URI"); throw new ServerException("No profile URI");
} }
if (empty($feeduri)) { if (array_key_exists('feedurl', $hints)) {
if (array_key_exists('feedurl', $hints)) { $feeduri = $hints['feedurl'];
$feeduri = $hints['feedurl']; } else {
}
}
if (empty($salmonuri)) {
if (array_key_exists('salmon', $hints)) {
$salmonuri = $hints['salmon'];
}
}
if (!$feeduri || !$salmonuri) {
// Get the canonical feed URI and check it
$discover = new FeedDiscovery(); $discover = new FeedDiscovery();
$feeduri = $discover->discoverFromURL($homeuri); $feeduri = $discover->discoverFromURL($homeuri);
}
$huburi = $discover->getAtomLink('hub'); if (array_key_exists('salmon', $hints)) {
$salmonuri = $discover->getAtomLink('salmon'); $salmonuri = $hints['salmon'];
} else {
if (!$huburi) { if (!$discover) {
// We can only deal with folks with a PuSH hub $discover = new FeedDiscovery();
throw new FeedSubNoHubException(); $discover->discoverFromFeedURL($hints['feedurl']);
} }
$salmonuri = $discover->getAtomLink('salmon');
}
if (array_key_exists('hub', $hints)) {
$huburi = $hints['hub'];
} else {
if (!$discover) {
$discover = new FeedDiscovery();
$discover->discoverFromFeedURL($hints['feedurl']);
}
$huburi = $discover->getAtomLink('hub');
}
if (!$huburi) {
// We can only deal with folks with a PuSH hub
throw new FeedSubNoHubException();
} }
$oprofile = new Ostatus_profile(); $oprofile = new Ostatus_profile();