mirror of
https://github.com/friendica/friendica
synced 2025-04-25 04:30:11 +00:00
Several performance improvements
This commit is contained in:
parent
9be09f7df5
commit
5b3145d7ce
15 changed files with 103 additions and 66 deletions
|
@ -24,6 +24,7 @@ namespace Friendica\Model;
|
|||
use Friendica\Content\Text\HTML;
|
||||
use Friendica\Core\Cache\Enum\Duration;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
|
@ -352,17 +353,18 @@ class APContact
|
|||
|
||||
if (!empty($apcontact['outbox'])) {
|
||||
if (!empty($local_owner)) {
|
||||
$outbox = ActivityPub\Transmitter::getOutbox($local_owner);
|
||||
$statuses_count = self::getStatusesCount($local_owner);
|
||||
} else {
|
||||
$outbox = ActivityPub::fetchContent($apcontact['outbox']);
|
||||
$statuses_count = $outbox['totalItems'] ?? 0;
|
||||
}
|
||||
if (!empty($outbox['totalItems'])) {
|
||||
if (!empty($statuses_count)) {
|
||||
// Mastodon seriously allows for this condition?
|
||||
// Jul 20 2021 - See https://chaos.social/@m11 for a negative posts count
|
||||
if ($outbox['totalItems'] < 0) {
|
||||
$outbox['totalItems'] = 0;
|
||||
if ($statuses_count < 0) {
|
||||
$statuses_count = 0;
|
||||
}
|
||||
$apcontact['statuses_count'] = $outbox['totalItems'];
|
||||
$apcontact['statuses_count'] = $statuses_count;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -483,6 +485,30 @@ class APContact
|
|||
return DBA::selectFirst('apcontact', [], ['url' => $apcontact['url']]) ?: [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the number of statuses for the given owner
|
||||
*
|
||||
* @param array $owner
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
private static function getStatusesCount(array $owner): int
|
||||
{
|
||||
$condition = [
|
||||
'private' => [Item::PUBLIC, Item::UNLISTED],
|
||||
'author-id' => Contact::getIdForURL($owner['url'], 0, false),
|
||||
'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT],
|
||||
'network' => Protocol::DFRN,
|
||||
'parent-network' => Protocol::FEDERATED,
|
||||
'deleted' => false,
|
||||
'visible' => true
|
||||
];
|
||||
|
||||
$count = Post::countPosts($condition);
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the given AP Contact as "to archive"
|
||||
*
|
||||
|
|
|
@ -100,7 +100,7 @@ class FContact
|
|||
|
||||
$interacted = DBA::count('contact-relation', ["`cid` = ? AND NOT `follows` AND `last-interaction` > ?", $contact['id'], $last_interaction]);
|
||||
$interacting = DBA::count('contact-relation', ["`relation-cid` = ? AND NOT `follows` AND `last-interaction` > ?", $contact['id'], $last_interaction]);
|
||||
$posts = Post::countPosts(['author-id' => $contact['id'], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]]);
|
||||
$posts = DBA::count('post', ['author-id' => $contact['id'], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]]);
|
||||
}
|
||||
|
||||
$fields = [
|
||||
|
|
|
@ -400,12 +400,12 @@ class Post
|
|||
AND (NOT `causer-blocked` OR `causer-id` = ? OR `causer-id` IS NULL) AND NOT `contact-blocked`
|
||||
AND ((NOT `contact-readonly` AND NOT `contact-pending` AND (`contact-rel` IN (?, ?)))
|
||||
OR `self` OR `gravity` != ? OR `contact-uid` = ?)
|
||||
AND NOT EXISTS (SELECT `uri-id` FROM `post-user` WHERE `uid` = ? AND `uri-id` = `" . $view . "`.`uri-id` AND `hidden`)
|
||||
AND NOT EXISTS (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `author-id` AND `blocked`)
|
||||
AND NOT EXISTS (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `owner-id` AND `blocked`)
|
||||
AND NOT EXISTS (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `author-id` AND `ignored` AND `gravity` = ?)
|
||||
AND NOT EXISTS (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `owner-id` AND `ignored` AND `gravity` = ?)",
|
||||
0, Contact::SHARING, Contact::FRIEND, GRAVITY_PARENT, 0, $uid, $uid, $uid, $uid, GRAVITY_PARENT, $uid, GRAVITY_PARENT]);
|
||||
AND NOT `" . $view . "`.`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `uid` = ? AND `hidden`)
|
||||
AND NOT `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `blocked`)
|
||||
AND NOT `owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `blocked`)
|
||||
AND NOT (`gravity` = ? AND `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored`))
|
||||
AND NOT (`gravity` = ? AND `owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored`))",
|
||||
0, Contact::SHARING, Contact::FRIEND, GRAVITY_PARENT, 0, $uid, $uid, $uid, GRAVITY_PARENT, $uid, GRAVITY_PARENT, $uid]);
|
||||
|
||||
$select_string = implode(', ', array_map([DBA::class, 'quoteIdentifier'], $selected));
|
||||
|
||||
|
|
|
@ -37,15 +37,16 @@ class Collection
|
|||
*
|
||||
* @param integer $uri_id
|
||||
* @param integer $type
|
||||
* @param integer $author_id
|
||||
* @param integer $cache_uid If set to a non zero value, the featured cache is cleared
|
||||
*/
|
||||
public static function add(int $uri_id, int $type, int $cache_uid = 0)
|
||||
public static function add(int $uri_id, int $type, int $author_id, int $cache_uid = 0)
|
||||
{
|
||||
if (empty($uri_id)) {
|
||||
throw new BadMethodCallException('Empty URI_id');
|
||||
}
|
||||
|
||||
DBA::insert('post-collection', ['uri-id' => $uri_id, 'type' => $type], Database::INSERT_IGNORE);
|
||||
DBA::insert('post-collection', ['uri-id' => $uri_id, 'type' => $type, 'author-id' => $author_id], Database::INSERT_IGNORE);
|
||||
|
||||
if (!empty($cache_uid) && ($type == self::FEATURED)) {
|
||||
DI::cache()->delete(ActivityPub\Transmitter::CACHEKEY_FEATURED . $cache_uid);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue