OStatus: garbage collect unused PuSH subscriptions when the last local subscriber unsubs

This commit is contained in:
Brion Vibber
2010-02-11 00:09:20 +00:00
parent 4ae760cb62
commit 71151b2583
3 changed files with 48 additions and 16 deletions

View File

@@ -234,13 +234,30 @@ class OStatusPlugin extends Plugin
}
}
/**
* Garbage collect unused feeds on unsubscribe
*/
function onEndUnsubscribe($user, $other)
{
$feed = Feedinfo::staticGet('profile_id', $other->id);
if ($feed) {
$sub = new Subscription();
$sub->subscribed = $other->id;
$sub->limit(1);
if (!$sub->find(true)) {
common_log(LOG_INFO, "Unsubscribing from now-unused feed $feed->feeduri on hub $feed->huburi");
$feed->unsubscribe();
}
}
return true;
}
function onCheckSchema() {
// warning: the autoincrement doesn't seem to set.
// alter table feedinfo change column id id int(11) not null auto_increment;
$schema = Schema::get();
$schema->ensureTable('feedinfo', Feedinfo::schemaDef());
$schema->ensureTable('hubsub', HubSub::schemaDef());
return true;
}
}
}