Don't always fetch parent posts

This commit is contained in:
Michael 2022-08-03 04:51:57 +00:00
parent 23ef4a99bb
commit 3463e34693
3 changed files with 19 additions and 14 deletions

View file

@ -265,12 +265,15 @@ class Processor
/**
* Prepares data for a message
*
* @param array $activity Activity array
* @param array $activity Activity array
* @param bool $fetch_parents
*
* @return array Internal item
*
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function createItem(array $activity): array
public static function createItem(array $activity, bool $fetch_parents = true): array
{
$item = [];
$item['verb'] = Activity::POST;
@ -305,7 +308,7 @@ class Processor
return [];
}
if (empty($activity['directmessage']) && ($activity['id'] != $activity['reply-to-id']) && !Post::exists(['uri' => $activity['reply-to-id']])) {
if ($fetch_parents && empty($activity['directmessage']) && ($activity['id'] != $activity['reply-to-id']) && !Post::exists(['uri' => $activity['reply-to-id']])) {
$result = self::fetchParent($activity);
if (!empty($result)) {
if (($item['thr-parent'] != $result) && Post::exists(['uri' => $result])) {

View file

@ -175,10 +175,11 @@ class Queue
* Process the activity with the given id
*
* @param integer $id
* @param bool $fetch_parents
*
* @return bool
*/
public static function process(int $id): bool
public static function process(int $id, bool $fetch_parents = true): bool
{
$entry = DBA::selectFirst('inbox-entry', [], ['id' => $id]);
if (empty($entry)) {
@ -215,7 +216,7 @@ class Queue
}
DBA::close($receivers);
if (!Receiver::routeActivities($activity, $type, $push)) {
if (!Receiver::routeActivities($activity, $type, $push, $fetch_parents)) {
self::remove($activity);
}
@ -236,7 +237,7 @@ class Queue
continue;
}
Logger::debug('Process leftover entry', $entry);
self::process($entry['id']);
self::process($entry['id'], false);
}
DBA::close($entries);
}
@ -272,7 +273,7 @@ class Queue
$entries = DBA::select('inbox-entry', ['id'], ["`in-reply-to-id` = ? AND `object-id` != ?", $uri, $uri]);
while ($entry = DBA::fetch($entries)) {
$count += 1;
self::process($entry['id']);
self::process($entry['id'], false);
}
DBA::close($entries);
return $count;

View file

@ -627,20 +627,21 @@ class Receiver
/**
* Route activities
*
* @param array $object_data
* @param string $type
* @param boolean $push
* @param array $object_data
* @param string $type
* @param bool $push
* @param bool $fetch_parents
*
* @return boolean Could the activity be routed?
*/
public static function routeActivities(array $object_data, string $type, bool $push): bool
public static function routeActivities(array $object_data, string $type, bool $push, bool $fetch_parents = true): bool
{
$activity = $object_data['object_activity'] ?? [];
switch ($type) {
case 'as:Create':
if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
$item = ActivityPub\Processor::createItem($object_data);
$item = ActivityPub\Processor::createItem($object_data, $fetch_parents);
ActivityPub\Processor::postItem($object_data, $item);
} elseif (in_array($object_data['object_type'], ['pt:CacheFile'])) {
// Unhandled Peertube activity
@ -652,7 +653,7 @@ class Receiver
case 'as:Invite':
if (in_array($object_data['object_type'], ['as:Event'])) {
$item = ActivityPub\Processor::createItem($object_data);
$item = ActivityPub\Processor::createItem($object_data, $fetch_parents);
ActivityPub\Processor::postItem($object_data, $item);
} else {
return false;
@ -678,7 +679,7 @@ class Receiver
$object_data['thread-completion'] = Contact::getIdForURL($actor);
$object_data['completion-mode'] = self::COMPLETION_ANNOUCE;
$item = ActivityPub\Processor::createItem($object_data);
$item = ActivityPub\Processor::createItem($object_data, $fetch_parents);
if (empty($item)) {
return false;
}