[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
This commit is contained in:
tenma 2019-08-14 00:43:34 +01:00 committed by Diogo Peralta Cordeiro
parent 83f179989e
commit 3852ad175f
3 changed files with 14 additions and 18 deletions

View File

@ -116,18 +116,17 @@ class apActorFollowersAction extends ManagedAction
*/
public static function generate_followers($profile, $since, $limit)
{
/* Fetch Followers */
$subs = [];
try {
$sub = Activitypub_profile::getSubscribers($profile, $since, $limit);
} 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);
}
} catch (NoResultException $e) {
// Just let the exception go on its merry way
}
return $subs;
}

View File

@ -116,18 +116,17 @@ class apActorFollowingAction extends ManagedAction
*/
public function generate_following($profile, $since, $limit)
{
/* Fetch Following */
$subs = [];
try {
$sub = Activitypub_profile::getSubscribed($profile, $since, $limit);
} 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);
}
} catch (NoResultException $e) {
// Just let the exception go on its merry way
}
return $subs;
}

View File

@ -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);