"Allfriends" now work again

This commit is contained in:
Michael 2020-08-03 19:21:31 +00:00
parent a36d305984
commit 14bb6daa5d
2 changed files with 41 additions and 139 deletions

View file

@ -26,6 +26,8 @@ use Friendica\Core\Logger;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\APContact;
use Friendica\Model\Contact;
use Friendica\Protocol\ActivityPub; use Friendica\Protocol\ActivityPub;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings; use Friendica\Util\Strings;
@ -218,12 +220,8 @@ class Relation
public static function countFollows(int $cid, array $condition = []) public static function countFollows(int $cid, array $condition = [])
{ {
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
['`id` IN ( ['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)',
SELECT `relation-cid` $cid]
FROM `contact-relation`
WHERE `cid` = ?
AND `follows`
)', $cid]
); );
return DI::dba()->count('contact', $condition); return DI::dba()->count('contact', $condition);
@ -243,24 +241,13 @@ class Relation
public static function listFollows(int $cid, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false) public static function listFollows(int $cid, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
{ {
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
['`id` IN ( ['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)',
SELECT `relation-cid` $cid]
FROM `contact-relation`
WHERE `cid` = ?
AND `follows`
)', $cid]
); );
$follows = DI::dba()->selectToArray( return DI::dba()->selectToArray('contact', [], $condition,
'contact', ['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']]
$condition,
[
'limit' => [$offset, $count],
'order' => [$shuffle ? 'RAND()' : 'name']
]
); );
return $follows;
} }
/** /**
@ -274,12 +261,8 @@ class Relation
public static function countFollowers(int $cid, array $condition = []) public static function countFollowers(int $cid, array $condition = [])
{ {
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
['`id` IN ( ['`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)',
SELECT `cid` $cid]
FROM `contact-relation`
WHERE `relation-cid` = ?
AND `follows`
)', $cid]
); );
return DI::dba()->count('contact', $condition); return DI::dba()->count('contact', $condition);
@ -299,21 +282,11 @@ class Relation
public static function listFollowers(int $cid, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false) public static function listFollowers(int $cid, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
{ {
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
['`id` IN ( ['`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)', $cid]
SELECT `cid`
FROM `contact-relation`
WHERE `relation-cid` = ?
AND `follows`
)', $cid]
); );
$followers = DI::dba()->selectToArray( $followers = DI::dba()->selectToArray('contact', [], $condition,
'contact', ['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']]
$condition,
[
'limit' => [$offset, $count],
'order' => [$shuffle ? 'RAND()' : 'name']
]
); );
return $followers; return $followers;
@ -332,16 +305,9 @@ class Relation
public static function countCommon(int $sourceId, int $targetId, array $condition = []) public static function countCommon(int $sourceId, int $targetId, array $condition = [])
{ {
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
['`id` IN ( ['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ?)
SELECT `relation-cid` AND `id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ?)',
FROM `contact-relation` $sourceId, $targetId]
WHERE `cid` = ?
)
AND `id` IN (
SELECT `relation-cid`
FROM `contact-relation`
WHERE `cid` = ?
)', $sourceId, $targetId]
); );
$total = DI::dba()->count('contact', $condition); $total = DI::dba()->count('contact', $condition);
@ -365,27 +331,13 @@ class Relation
public static function listCommon(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false) public static function listCommon(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
{ {
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
["`id` IN ( ["`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)
SELECT `relation-cid` AND `id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)",
FROM `contact-relation` $sourceId, $targetId]
WHERE `cid` = ?
AND `follows`
)
AND `id` IN (
SELECT `relation-cid`
FROM `contact-relation`
WHERE `cid` = ?
AND `follows`
)", $sourceId, $targetId]
); );
$contacts = DI::dba()->selectToArray( $contacts = DI::dba()->selectToArray('contact', [], $condition,
'contact', ['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']]
$condition,
[
'limit' => [$offset, $count],
'order' => [$shuffle ? 'name' : 'RAND()'],
]
); );
return $contacts; return $contacts;
@ -404,18 +356,9 @@ class Relation
public static function countCommonFollows(int $sourceId, int $targetId, array $condition = []) public static function countCommonFollows(int $sourceId, int $targetId, array $condition = [])
{ {
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
['`id` IN ( ['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)
SELECT `relation-cid` AND `id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)',
FROM `contact-relation` $sourceId, $targetId]
WHERE `cid` = ?
AND `follows`
)
AND `id` IN (
SELECT `relation-cid`
FROM `contact-relation`
WHERE `cid` = ?
AND `follows`
)', $sourceId, $targetId]
); );
$total = DI::dba()->count('contact', $condition); $total = DI::dba()->count('contact', $condition);
@ -438,27 +381,13 @@ class Relation
public static function listCommonFollows(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false) public static function listCommonFollows(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
{ {
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
["`id` IN ( ["`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)
SELECT `relation-cid` AND `id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)",
FROM `contact-relation` $sourceId, $targetId]
WHERE `cid` = ?
AND `follows`
)
AND `id` IN (
SELECT `relation-cid`
FROM `contact-relation`
WHERE `cid` = ?
AND `follows`
)", $sourceId, $targetId]
); );
$contacts = DI::dba()->selectToArray( $contacts = DI::dba()->selectToArray('contact', [], $condition,
'contact', ['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']]
$condition,
[
'limit' => [$offset, $count],
'order' => [$shuffle ? 'name' : 'RAND()'],
]
); );
return $contacts; return $contacts;
@ -476,23 +405,12 @@ class Relation
public static function countCommonFollowers(int $sourceId, int $targetId, array $condition = []) public static function countCommonFollowers(int $sourceId, int $targetId, array $condition = [])
{ {
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
['`id` IN ( ["`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)
SELECT `cid` AND `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)",
FROM `contact-relation` $sourceId, $targetId]
WHERE `relation-cid` = ?
AND `follows`
)
AND `id` IN (
SELECT `cid`
FROM `contact-relation`
WHERE `relation-cid` = ?
AND `follows`
)', $sourceId, $targetId]
); );
$total = DI::dba()->count('contact', $condition); return DI::dba()->count('contact', $condition);
return $total;
} }
/** /**
@ -510,29 +428,13 @@ class Relation
public static function listCommonFollowers(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false) public static function listCommonFollowers(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
{ {
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
["`id` IN ( ["`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)
SELECT `cid` AND `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)",
FROM `contact-relation` $sourceId, $targetId]
WHERE `relation-cid` = ?
AND `follows`
)
AND `id` IN (
SELECT `cid`
FROM `contact-relation`
WHERE `relation-cid` = ?
AND `follows`
)", $sourceId, $targetId]
); );
$contacts = DI::dba()->selectToArray( return DI::dba()->selectToArray('contact', [], $condition,
'contact', ['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']]
$condition,
[
'limit' => [$offset, $count],
'order' => [$shuffle ? 'name' : 'RAND()'],
]
); );
return $contacts;
} }
} }

View file

@ -54,20 +54,20 @@ class AllFriends extends BaseModule
$uid = $app->user['uid']; $uid = $app->user['uid'];
$contact = Model\Contact::getById($cid, ['name', 'url', 'photo', 'uid', 'id']); $contact = Model\Contact::getById($cid, []);
if (empty($contact)) { if (empty($contact)) {
throw new HTTPException\BadRequestException(DI::l10n()->t('Invalid contact.')); throw new HTTPException\BadRequestException(DI::l10n()->t('Invalid contact.'));
} }
DI::page()['aside'] = ""; DI::page()['aside'] = "";
Model\Profile::load($app, "", Model\Contact::getByURL($contact["url"], false)); Model\Profile::load($app, "", $contact);
$total = Model\Contact\Relation::countFollows($cid); $total = Model\Contact\Relation::countFollows($cid);
$pager = new Pager(DI::l10n(), DI::args()->getQueryString()); $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
$friends = Model\Contact\Relation::listFollows($cid, [], $pager->getStart(), $pager->getItemsPerPage()); $friends = Model\Contact\Relation::listFollows($cid, [], $pager->getItemsPerPage(), $pager->getStart());
if (empty($friends)) { if (empty($friends)) {
return DI::l10n()->t('No friends to display.'); return DI::l10n()->t('No friends to display.');
} }