mirror of
https://github.com/friendica/friendica
synced 2025-04-25 16:30:10 +00:00
Several performance improvements
This commit is contained in:
parent
9be09f7df5
commit
5b3145d7ce
15 changed files with 103 additions and 66 deletions
|
@ -679,7 +679,7 @@ class Processor
|
|||
* Fetch the Uri-Id of a post for the "featured" collection
|
||||
*
|
||||
* @param array $activity
|
||||
* @return null|int
|
||||
* @return null|array
|
||||
*/
|
||||
private static function getUriIdForFeaturedCollection(array $activity)
|
||||
{
|
||||
|
@ -697,7 +697,7 @@ class Processor
|
|||
}
|
||||
}
|
||||
|
||||
$parent = Post::selectFirst(['uri-id'], ['uri' => $activity['object_id']]);
|
||||
$parent = Post::selectFirst(['uri-id', 'author-id'], ['uri' => $activity['object_id']]);
|
||||
if (empty($parent['uri-id'])) {
|
||||
if (self::fetchMissingActivity($activity['object_id'], $activity, '', Receiver::COMPLETION_AUTO)) {
|
||||
$parent = Post::selectFirst(['uri-id'], ['uri' => $activity['object_id']]);
|
||||
|
@ -705,7 +705,7 @@ class Processor
|
|||
}
|
||||
|
||||
if (!empty($parent['uri-id'])) {
|
||||
return $parent['uri-id'];
|
||||
$parent;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -718,14 +718,14 @@ class Processor
|
|||
*/
|
||||
public static function addToFeaturedCollection(array $activity)
|
||||
{
|
||||
$uriid = self::getUriIdForFeaturedCollection($activity);
|
||||
if (empty($uriid)) {
|
||||
$post = self::getUriIdForFeaturedCollection($activity);
|
||||
if (empty($post)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Logger::debug('Add post to featured collection', ['uri-id' => $uriid]);
|
||||
Logger::debug('Add post to featured collection', ['post' => $post]);
|
||||
|
||||
Post\Collection::add($uriid, Post\Collection::FEATURED);
|
||||
Post\Collection::add($post['uri-id'], Post\Collection::FEATURED, $post['author-id']);
|
||||
Queue::remove($activity);
|
||||
}
|
||||
|
||||
|
@ -736,14 +736,14 @@ class Processor
|
|||
*/
|
||||
public static function removeFromFeaturedCollection(array $activity)
|
||||
{
|
||||
$uriid = self::getUriIdForFeaturedCollection($activity);
|
||||
if (empty($uriid)) {
|
||||
$post = self::getUriIdForFeaturedCollection($activity);
|
||||
if (empty($post)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Logger::debug('Remove post from featured collection', ['uri-id' => $uriid]);
|
||||
Logger::debug('Remove post from featured collection', ['post' => $post]);
|
||||
|
||||
Post\Collection::remove($uriid, Post\Collection::FEATURED);
|
||||
Post\Collection::remove($post['uri-id'], Post\Collection::FEATURED);
|
||||
Queue::remove($activity);
|
||||
}
|
||||
|
||||
|
@ -1335,10 +1335,10 @@ class Processor
|
|||
}
|
||||
$id = Item::fetchByLink($post['id']);
|
||||
if (!empty($id)) {
|
||||
$item = Post::selectFirst(['uri-id', 'featured'], ['id' => $id]);
|
||||
$item = Post::selectFirst(['uri-id', 'featured', 'author-id'], ['id' => $id]);
|
||||
if (!empty($item['uri-id'])) {
|
||||
if (!$item['featured']) {
|
||||
Post\Collection::add($item['uri-id'], Post\Collection::FEATURED);
|
||||
Post\Collection::add($item['uri-id'], Post\Collection::FEATURED, $item['author-id']);
|
||||
Logger::debug('Added featured post', ['uri-id' => $item['uri-id'], 'contact' => $url]);
|
||||
$new++;
|
||||
} else {
|
||||
|
|
|
@ -59,7 +59,6 @@ class Transmitter
|
|||
{
|
||||
const CACHEKEY_FEATURED = 'transmitter:getFeatured:';
|
||||
const CACHEKEY_CONTACTS = 'transmitter:getContacts:';
|
||||
const CACHEKEY_OUTBOX = 'transmitter:getOutbox:';
|
||||
|
||||
/**
|
||||
* Add relay servers to the list of inboxes
|
||||
|
@ -251,14 +250,6 @@ class Transmitter
|
|||
*/
|
||||
public static function getOutbox(array $owner, int $page = null, string $requester = '', bool $nocache = false): array
|
||||
{
|
||||
if (empty($page)) {
|
||||
$cachekey = self::CACHEKEY_OUTBOX . $owner['uid'];
|
||||
$result = DI::cache()->get($cachekey);
|
||||
if (!$nocache && !is_null($result)) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
$condition = ['private' => [Item::PUBLIC, Item::UNLISTED]];
|
||||
|
||||
if (!empty($requester)) {
|
||||
|
@ -283,12 +274,12 @@ class Transmitter
|
|||
'visible' => true
|
||||
]);
|
||||
|
||||
$count = Post::count($condition);
|
||||
$apcontact = APContact::getByURL($owner['url']);
|
||||
|
||||
$data = ['@context' => ActivityPub::CONTEXT];
|
||||
$data['id'] = DI::baseUrl() . '/outbox/' . $owner['nickname'];
|
||||
$data['type'] = 'OrderedCollection';
|
||||
$data['totalItems'] = $count;
|
||||
$data['totalItems'] = $apcontact['statuses_count'] ?? 0;
|
||||
|
||||
if (!empty($page)) {
|
||||
$data['id'] .= '?' . http_build_query(['page' => $page]);
|
||||
|
@ -316,15 +307,17 @@ class Transmitter
|
|||
$data['next'] = DI::baseUrl() . '/outbox/' . $owner['nickname'] . '?page=' . ($page + 1);
|
||||
}
|
||||
|
||||
// Fix the cached total item count when it is lower than the real count
|
||||
$total = (($page - 1) * 20) + $data['totalItems'];
|
||||
if ($total > $data['totalItems']) {
|
||||
$data['totalItems'] = $total;
|
||||
}
|
||||
|
||||
$data['partOf'] = DI::baseUrl() . '/outbox/' . $owner['nickname'];
|
||||
|
||||
$data['orderedItems'] = $list;
|
||||
}
|
||||
|
||||
if (!empty($cachekey)) {
|
||||
DI::cache()->set($cachekey, $data, Duration::DAY);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue