From 06c0c4a3de7c51f434efa9270ac5202be26cdfcf Mon Sep 17 00:00:00 2001 From: BentiGorlich Date: Tue, 25 Jun 2024 18:10:18 +0200 Subject: [PATCH] Only update `lastOriginUpdate` every 3 hours - every 3 hours, not on every incoming activity - only for activities of type `Announce(Create)`, so excluding `Announce(Like)` activities, which are by far the most common ones --- .../ActivityPub/Inbox/ActivityHandler.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/MessageHandler/ActivityPub/Inbox/ActivityHandler.php b/src/MessageHandler/ActivityPub/Inbox/ActivityHandler.php index 94e90e4cd..1950ace1b 100644 --- a/src/MessageHandler/ActivityPub/Inbox/ActivityHandler.php +++ b/src/MessageHandler/ActivityPub/Inbox/ActivityHandler.php @@ -93,14 +93,17 @@ private function handle(?array $payload) } if ('Announce' === $payload['type']) { - $actor = $this->manager->findActorOrCreate($payload['actor']); - if ($actor instanceof Magazine) { - $actor->lastOriginUpdate = new \DateTime(); - $this->entityManager->persist($actor); - $this->entityManager->flush(); - } // we check for an array here, because boosts are announces with an url (string) as the object if (\is_array($payload['object'])) { + $actorObject = $this->manager->findActorOrCreate($payload['actor']); + if ($actorObject instanceof Magazine && $actorObject->lastOriginUpdate < (new \DateTime())->modify('-3 hours')) { + if (isset($payload['object']['type']) && 'Create' === $payload['object']['type']) { + $actorObject->lastOriginUpdate = new \DateTime(); + $this->entityManager->persist($actorObject); + $this->entityManager->flush(); + } + } + $payload = $payload['object']; $actor = $payload['actor'] ?? $payload['attributedTo'] ?? null; if ($actor) {