Merge pull request #11817 from annando/double-processing
Avoid processing the same activity
This commit is contained in:
commit
bd246b8cc2
|
@ -59,6 +59,36 @@ class Processor
|
||||||
{
|
{
|
||||||
const CACHEKEY_FETCH_ACTIVITY = 'processor:fetchMissingActivity:';
|
const CACHEKEY_FETCH_ACTIVITY = 'processor:fetchMissingActivity:';
|
||||||
const CACHEKEY_JUST_FETCHED = 'processor:isJustFetched:';
|
const CACHEKEY_JUST_FETCHED = 'processor:isJustFetched:';
|
||||||
|
|
||||||
|
static $processed = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an activity id to the list of processed ids
|
||||||
|
*
|
||||||
|
* @param string $id
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function addActivityId(string $id)
|
||||||
|
{
|
||||||
|
self::$processed[] = $id;
|
||||||
|
if (count(self::$processed) > 100) {
|
||||||
|
self::$processed = array_slice(self::$processed, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given has just been processed
|
||||||
|
*
|
||||||
|
* @param string $id
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static function isProcessed(string $id): bool
|
||||||
|
{
|
||||||
|
return in_array($id, self::$processed);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts the tag character (#, @, !) from mention links
|
* Extracts the tag character (#, @, !) from mention links
|
||||||
*
|
*
|
||||||
|
@ -275,6 +305,13 @@ class Processor
|
||||||
*/
|
*/
|
||||||
public static function createItem(array $activity, bool $fetch_parents = true): array
|
public static function createItem(array $activity, bool $fetch_parents = true): array
|
||||||
{
|
{
|
||||||
|
if (self::isProcessed($activity['id'])) {
|
||||||
|
Logger::info('Id is already processed', ['id' => $activity['id']]);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
self::addActivityId($activity['id']);
|
||||||
|
|
||||||
$item = [];
|
$item = [];
|
||||||
$item['verb'] = Activity::POST;
|
$item['verb'] = Activity::POST;
|
||||||
$item['thr-parent'] = $activity['reply-to-id'];
|
$item['thr-parent'] = $activity['reply-to-id'];
|
||||||
|
@ -308,7 +345,7 @@ class Processor
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DI::config()->get('system', 'fetch_parents')) {
|
if (!in_array(0, $activity['receiver']) && !DI::config()->get('system', 'fetch_parents')) {
|
||||||
$fetch_parents = false;
|
$fetch_parents = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1045,6 +1082,10 @@ class Processor
|
||||||
$success = true;
|
$success = true;
|
||||||
} else {
|
} else {
|
||||||
Logger::notice('Item insertion aborted', ['uri' => $item['uri'], 'uid' => $item['uid']]);
|
Logger::notice('Item insertion aborted', ['uri' => $item['uri'], 'uid' => $item['uid']]);
|
||||||
|
if (($item['uid'] == 0) && (count($activity['receiver']) > 1)) {
|
||||||
|
Logger::info('Public item was aborted. We skip for all users.', ['uri' => $item['uri']]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($item['uid'] == 0) {
|
if ($item['uid'] == 0) {
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
namespace Friendica\Protocol\ActivityPub;
|
namespace Friendica\Protocol\ActivityPub;
|
||||||
|
|
||||||
use Friendica\Core\Logger;
|
use Friendica\Core\Logger;
|
||||||
|
use Friendica\Core\System;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
@ -199,7 +200,7 @@ class Queue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::debug('Processing queue entry', ['id' => $entry['id'], 'type' => $entry['type'], 'object-type' => $entry['object-type'], 'uri' => $entry['object-id'], 'in-reply-to' => $entry['in-reply-to-id']]);
|
Logger::debug('Processing queue entry', ['id' => $entry['id'], 'type' => $entry['type'], 'object-type' => $entry['object-type'], 'uri' => $entry['object-id'], 'in-reply-to' => $entry['in-reply-to-id'], 'callstack' => System::callstack(20)]);
|
||||||
|
|
||||||
$activity = json_decode($entry['activity'], true);
|
$activity = json_decode($entry['activity'], true);
|
||||||
$type = $entry['type'];
|
$type = $entry['type'];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user