forked from GNUsocial/gnu-social
OStatus/FeedSub: tweaked PuSH feed garbage collection so other plugins can declare usage of a low-level feed or an OStatus profile besides profile subscriptions & group memberships.
SubMirror: redid add-mirror frontend to accept a feed URL, then pass that on to OStatus, instead of pulling from your subscriptions. Profile: tweaked subscriberCount() so it doesn't subtract 1 for foreign profiles who aren't subscribed to themselves; instead excludes the self-subscription in the count query. Memcached_DataObject: tweak to avoid extra error spew in the DB error raising Work in progress: tweaking feedsub garbage collection so we can count other uses
This commit is contained in:
@@ -255,6 +255,9 @@ class FeedSub extends Memcached_DataObject
|
||||
/**
|
||||
* Send a PuSH unsubscription request to the hub for this feed.
|
||||
* The hub will later send us a confirmation POST to /main/push/callback.
|
||||
* Warning: this will cancel the subscription even if someone else in
|
||||
* the system is using it. Most callers will want garbageCollect() instead,
|
||||
* which confirms there's no uses left.
|
||||
*
|
||||
* @return bool true on success, false on failure
|
||||
* @throws ServerException if feed state is not valid
|
||||
@@ -275,6 +278,33 @@ class FeedSub extends Memcached_DataObject
|
||||
return $this->doSubscribe('unsubscribe');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there are any active local uses of this feed, and if not then
|
||||
* make sure it's inactive, unsubscribing if necessary.
|
||||
*
|
||||
* @return boolean true if the subscription is now inactive, false if still active.
|
||||
*/
|
||||
public function garbageCollect()
|
||||
{
|
||||
if ($this->sub_state == '' || $this->sub_state == 'inactive') {
|
||||
// No active PuSH subscription, we can just leave it be.
|
||||
return true;
|
||||
} else {
|
||||
// PuSH subscription is either active or in an indeterminate state.
|
||||
// Check if we're out of subscribers, and if so send an unsubscribe.
|
||||
$count = 0;
|
||||
Event::handle('FeedSubSubscriberCount', array($this, &$count));
|
||||
|
||||
if ($count) {
|
||||
common_log(LOG_INFO, __METHOD__ . ': ok, ' . $count . ' user(s) left for ' . $this->uri);
|
||||
return false;
|
||||
} else {
|
||||
common_log(LOG_INFO, __METHOD__ . ': unsubscribing, no users left for ' . $this->uri);
|
||||
return $this->unsubscribe();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function doSubscribe($mode)
|
||||
{
|
||||
$orig = clone($this);
|
||||
|
||||
@@ -215,22 +215,13 @@ class Ostatus_profile extends Memcached_DataObject
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a PuSH unsubscription request to the hub for this feed.
|
||||
* The hub will later send us a confirmation POST to /main/push/callback.
|
||||
* Check if this remote profile has any active local subscriptions, and
|
||||
* if not drop the PuSH subscription feed.
|
||||
*
|
||||
* @return bool true on success, false on failure
|
||||
* @throws ServerException if feed state is not valid
|
||||
*/
|
||||
public function unsubscribe() {
|
||||
$feedsub = FeedSub::staticGet('uri', $this->feeduri);
|
||||
if (!$feedsub || $feedsub->sub_state == '' || $feedsub->sub_state == 'inactive') {
|
||||
// No active PuSH subscription, we can just leave it be.
|
||||
return true;
|
||||
} else {
|
||||
// PuSH subscription is either active or in an indeterminate state.
|
||||
// Send an unsubscribe.
|
||||
return $feedsub->unsubscribe();
|
||||
}
|
||||
$this->garbageCollect();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,6 +231,21 @@ class Ostatus_profile extends Memcached_DataObject
|
||||
* @return boolean
|
||||
*/
|
||||
public function garbageCollect()
|
||||
{
|
||||
$feedsub = FeedSub::staticGet('uri', $this->feeduri);
|
||||
return $feedsub->garbageCollect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this remote profile has any active local subscriptions, so the
|
||||
* PuSH subscription layer can decide if it can drop the feed.
|
||||
*
|
||||
* This gets called via the FeedSubSubscriberCount event when running
|
||||
* FeedSub::garbageCollect().
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function subscriberCount()
|
||||
{
|
||||
if ($this->isGroup()) {
|
||||
$members = $this->localGroup()->getMembers(0, 1);
|
||||
@@ -247,13 +253,14 @@ class Ostatus_profile extends Memcached_DataObject
|
||||
} else {
|
||||
$count = $this->localProfile()->subscriberCount();
|
||||
}
|
||||
if ($count == 0) {
|
||||
common_log(LOG_INFO, "Unsubscribing from now-unused remote feed $this->feeduri");
|
||||
$this->unsubscribe();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
common_log(LOG_INFO, __METHOD__ . " SUB COUNT BEFORE: $count");
|
||||
|
||||
// Other plugins may be piggybacking on OStatus without having
|
||||
// an active group or user-to-user subscription we know about.
|
||||
Event::handle('Ostatus_profileSubscriberCount', array($this, &$count));
|
||||
common_log(LOG_INFO, __METHOD__ . " SUB COUNT AFTER: $count");
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user