From 9733f3c02c8d37b9699712f4f01d4ec4c3323aef Mon Sep 17 00:00:00 2001 From: tenma Date: Wed, 14 Aug 2019 00:43:34 +0100 Subject: [PATCH] [AP] Fix Follow collections Activitypub_profile: - Fix subscription-counter getter functions, invalid profiles were being counted apActorFollowingAction: - Small rewrite of generate_following, didn't make sense to not use try-catch block apActorFollowersAction: - Small rewrite of generate_followers, didn't make sense to not use try-catch block --- plugins/ActivityPub/actions/apactorfollowers.php | 13 ++++++------- plugins/ActivityPub/actions/apactorfollowing.php | 13 ++++++------- plugins/ActivityPub/classes/Activitypub_profile.php | 6 ++---- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/plugins/ActivityPub/actions/apactorfollowers.php b/plugins/ActivityPub/actions/apactorfollowers.php index 5f22bc06e7..710877fc60 100644 --- a/plugins/ActivityPub/actions/apactorfollowers.php +++ b/plugins/ActivityPub/actions/apactorfollowers.php @@ -116,19 +116,18 @@ class apActorFollowersAction extends ManagedAction */ public static function generate_followers($profile, $since, $limit) { - /* Fetch Followers */ + $subs = []; try { $sub = Activitypub_profile::getSubscribers($profile, $since, $limit); + + /* Get followers' URLs */ + foreach ($sub as $s) { + $subs[] = ActivityPubPlugin::actor_uri($s); + } } catch (NoResultException $e) { // Just let the exception go on its merry way } - /* Get followers' URLs */ - $subs = []; - foreach ($sub as $s) { - $subs[] = ActivityPubPlugin::actor_uri($s); - } - return $subs; } } diff --git a/plugins/ActivityPub/actions/apactorfollowing.php b/plugins/ActivityPub/actions/apactorfollowing.php index 8d92b93641..8cf4ab51a4 100644 --- a/plugins/ActivityPub/actions/apactorfollowing.php +++ b/plugins/ActivityPub/actions/apactorfollowing.php @@ -116,19 +116,18 @@ class apActorFollowingAction extends ManagedAction */ public function generate_following($profile, $since, $limit) { - /* Fetch Following */ + $subs = []; try { $sub = Activitypub_profile::getSubscribed($profile, $since, $limit); + + /* Get followed' URLs */ + foreach ($sub as $s) { + $subs[] = ActivityPubPlugin::actor_uri($s); + } } catch (NoResultException $e) { // Just let the exception go on its merry way } - /* Get followed' URLs */ - $subs = []; - foreach ($sub as $s) { - $subs[] = ActivityPubPlugin::actor_uri($s); - } - return $subs; } } diff --git a/plugins/ActivityPub/classes/Activitypub_profile.php b/plugins/ActivityPub/classes/Activitypub_profile.php index 9beec0058c..80c73d8b09 100644 --- a/plugins/ActivityPub/classes/Activitypub_profile.php +++ b/plugins/ActivityPub/classes/Activitypub_profile.php @@ -505,9 +505,8 @@ class Activitypub_profile extends Managed_DataObject $sub = new Subscription(); $sub->subscribed = $profile->id; - $sub->joinAdd(['subscriber', 'user:id'], 'LEFT'); - $sub->joinAdd(['subscriber', 'activitypub_profile:profile_id'], 'LEFT'); $sub->whereAdd('subscriber != subscribed'); + $sub->whereAdd('subscriber IN (SELECT id FROM user UNION SELECT profile_id FROM activitypub_profile)'); $cnt = $sub->count('distinct subscriber'); self::cacheSet(sprintf('activitypub_profile:subscriberCount:%d', $profile->id), $cnt); @@ -532,9 +531,8 @@ class Activitypub_profile extends Managed_DataObject $sub = new Subscription(); $sub->subscriber = $profile->id; - $sub->joinAdd(['subscribed', 'user:id'], 'LEFT'); - $sub->joinAdd(['subscribed', 'activitypub_profile:profile_id'], 'LEFT'); $sub->whereAdd('subscriber != subscribed'); + $sub->whereAdd('subscribed IN (SELECT id FROM user UNION SELECT profile_id FROM activitypub_profile)'); $cnt = $sub->count('distinct subscribed'); self::cacheSet(sprintf('activitypub_profile:subscriptionCount:%d', $profile->id), $cnt);