Additional checks against fetch loops

This commit is contained in:
Michael 2024-08-14 05:17:39 +00:00
parent 5904ade15b
commit c9ba460817
2 changed files with 16 additions and 6 deletions

View file

@ -189,10 +189,11 @@ class Queue
*
* @param integer $id
* @param bool $fetch_parents
* @param array $parent
*
* @return bool
*/
public static function process(int $id, bool $fetch_parents = true): bool
public static function process(int $id, bool $fetch_parents = true, array $parent = []): bool
{
$entry = DBA::selectFirst('inbox-entry', [], ['id' => $id]);
if (empty($entry)) {
@ -226,6 +227,14 @@ class Queue
$activity['worker-id'] = $entry['wid'];
$activity['recursion-depth'] = 0;
if (!empty($parent['children'])) {
$activity['children'] = array_merge($activity['children'] ?? [], $parent['children']);
}
if (!empty($parent['callstack'])) {
$activity['callstack'] = array_merge($activity['callstack'] ?? [], $parent['callstack']);
}
if (empty($activity['thread-children-type'])) {
$activity['thread-children-type'] = $type;
}
@ -349,15 +358,16 @@ class Queue
* Process all activities that are children of a given post url
*
* @param string $uri
* @param array $parent
* @return int
*/
public static function processReplyByUri(string $uri): int
public static function processReplyByUri(string $uri, array $parent = []): int
{
$count = 0;
$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'], false);
self::process($entry['id'], false, $parent);
}
DBA::close($entries);
return $count;

View file

@ -728,6 +728,9 @@ class Receiver
self::addArrivedId($object_data['object_id']);
}
$object_data['children'] = $activity['children'] ?? [];
$object_data['callstack'] = $activity['callstack'] ?? [];
$decouple = DI::config()->get('system', 'decoupled_receiver') && !in_array($completion, [self::COMPLETION_MANUAL, self::COMPLETION_ANNOUNCE]) && empty($object_data['directmessage']);
if ($decouple && ($trust_source || DI::config()->get('debug', 'ap_inbox_store_untrusted'))) {
@ -756,9 +759,6 @@ class Receiver
$object_data['recursion-depth'] = $activity['recursion-depth'];
}
$object_data['children'] = $activity['children'] ?? [];
$object_data['callstack'] = $activity['callstack'] ?? [];
if (!self::routeActivities($object_data, $type, $push, true, $uid)) {
self::storeUnhandledActivity(true, $type, $object_data, $activity, $body, $uid, $trust_source, $push, $signer);
Queue::remove($object_data);