More prevention of double processing of the same content

This commit is contained in:
Michael 2022-08-06 17:06:55 +00:00
parent 8b698b183d
commit 87a945b295
8 changed files with 141 additions and 52 deletions

View file

@ -586,11 +586,19 @@ class Receiver
$object_data['object_activity'] = $activity;
}
if (($type == 'as:Create') && Queue::exists($object_data['object_id'], $type)) {
Logger::info('The activity is already added.', ['id' => $object_data['object_id']]);
return true;
}
if (($type == 'as:Create') && $trust_source) {
if (self::hasArrived($object_data['object_id'])) {
Logger::info('The activity already arrived.', ['id' => $object_data['object_id']]);
return true;
}
self::addArrivedId($object_data['object_id']);
if (Queue::exists($object_data['object_id'], $type)) {
Logger::info('The activity is already added.', ['id' => $object_data['object_id']]);
return true;
}
}
if (DI::config()->get('system', 'decoupled_receiver') && ($trust_source || DI::config()->get('debug', 'ap_inbox_store_untrusted'))) {
$object_data = Queue::add($object_data, $type, $uid, $http_signer, $push, $trust_source);
}
@ -1883,4 +1891,29 @@ class Receiver
return $object_data;
}
/**
* Add an object id to the list of arrived activities
*
* @param string $id
*
* @return void
*/
private static function addArrivedId(string $id)
{
DBA::delete('arrived-activity', ["`received` < ?", DateTimeFormat::utc('now - 5 minutes')]);
DBA::insert('arrived-activity', ['object-id' => $id, 'received' => DateTimeFormat::utcNow()]);
}
/**
* Checks if the given object already arrived before
*
* @param string $id
*
* @return boolean
*/
private static function hasArrived(string $id): bool
{
return DBA::exists('arrived-activity', ['object-id' => $id]);
}
}