From a9f0003e809d46093e783d2079be7a952b5f5e0d Mon Sep 17 00:00:00 2001 From: winter Date: Mon, 31 Mar 2025 21:29:22 +0100 Subject: implement backfilling for newly discovered actors --- Digitigrade/Model/Actor.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'Digitigrade/Model/Actor.php') diff --git a/Digitigrade/Model/Actor.php b/Digitigrade/Model/Actor.php index d7fde42..d18c1f5 100644 --- a/Digitigrade/Model/Actor.php +++ b/Digitigrade/Model/Actor.php @@ -2,10 +2,13 @@ namespace Digitigrade\Model; use Digitigrade\Db; +use Digitigrade\Job\ProcessIncomingPush; +use Digitigrade\Job\ProcessIncomingSimplePush; use Digitigrade\Notification\PendingFollowActionedNotif; use Digitigrade\Notification\PokeNotif; use Digitigrade\Notification\UnblockNotif; use Digitigrade\Notification\UnfollowNotif; +use Digitigrade\Pagination; use Digitigrade\PokeVerb; use Digitigrade\RpcException; use Digitigrade\RpcReceiver; @@ -90,6 +93,10 @@ class Actor extends PushableModel implements RpcReceiver { $this->saveExtensions(); } + protected function onNewlyDiscovered() { + $this->backfill(); + } + private function findExtensions() { $pdo = Db::getInstance()->getPdo(); $stmt = $pdo->prepare('SELECT uri, data FROM actor_extension WHERE actor_id = ?'); @@ -139,6 +146,40 @@ class Actor extends PushableModel implements RpcReceiver { return self::findByUri($uri); } + /** + * Fetches this actor's remote feeds and all objects listed by them. + * @param ?int $limit Maximum number of objects to fetch + * @return void + */ + public function backfill(?int $limit = null) { + if (isset($this->endpoints->fullFeed)) { + $this->backfillFromFullFeed($limit); + } else { + $this->backfillFromBasicFeed($limit); + } + } + + private function backfillFromFullFeed(?int $limit) { + $pagination = Pagination::fromUri($this->endpoints->fullFeed); + for ($i = 0; isset($limit) ? ($i < $limit) : true; $i++) { + $item = $pagination->next(); + if ($item === false) + break; + // pretend they're pushes ... it's good enough + (new ProcessIncomingPush($item))->submit(); + } + } + + private function backfillFromBasicFeed(?int $limit) { + $pagination = Pagination::fromUri($this->endpoints->basicFeed); + for ($i = 0; isset($limit) ? ($i < $limit) : true; $i++) { + $uri = $pagination->next(); + if ($uri === false) + break; + (new ProcessIncomingSimplePush($uri))->submit(); + } + } + public function rpcCall(string $method, array $args, string $customEndpoint = null) { // $args = [Actor $actingAs, ?string $requestBody] if (!$this->isLocal) { -- cgit v1.3