diff --git a/lib/Db/CacheActorsRequest.php b/lib/Db/CacheActorsRequest.php index 7899f768..a33603a4 100644 --- a/lib/Db/CacheActorsRequest.php +++ b/lib/Db/CacheActorsRequest.php @@ -38,7 +38,7 @@ use OCP\DB\Exception as DBException; use OCP\DB\QueryBuilder\IQueryBuilder; class CacheActorsRequest extends CacheActorsRequestBuilder { - public const CACHE_TTL = 60 * 24; // 1d + public const CACHE_TTL = 60 * 24 * 10; // 10d /** diff --git a/lib/Interfaces/Actor/PersonInterface.php b/lib/Interfaces/Actor/PersonInterface.php index 256d5389..d0a15af1 100644 --- a/lib/Interfaces/Actor/PersonInterface.php +++ b/lib/Interfaces/Actor/PersonInterface.php @@ -125,7 +125,7 @@ class PersonInterface extends AbstractActivityPubInterface implements IActivityP break; case Delete::TYPE: - $this->deleteActor($item); + $this->delete($item); break; } } @@ -141,14 +141,19 @@ class PersonInterface extends AbstractActivityPubInterface implements IActivityP } } - public function deleteActor(Person $actor): void { - $this->actionsRequest->deleteByActor($actor->getId()); - $this->cacheActorsRequest->deleteCacheById($actor->getId()); - $this->cacheDocumentsRequest->deleteByParent($actor->getId()); - $this->requestQueueRequest->deleteByAuthor($actor->getId()); - $this->followsRequest->deleteRelatedId($actor->getId()); - $this->deleteStreamFromActor($actor); + public function delete(ACore $item): void { + if (!($item instanceof Person)) { + return; + } + + $this->actionsRequest->deleteByActor($item->getId()); + $this->cacheActorsRequest->deleteCacheById($item->getId()); + $this->cacheDocumentsRequest->deleteByParent($item->getId()); + $this->requestQueueRequest->deleteByAuthor($item->getId()); + $this->followsRequest->deleteRelatedId($item->getId()); + + $this->deleteStreamFromActor($item); } diff --git a/lib/Service/AccountService.php b/lib/Service/AccountService.php index 679becb1..eb5a10f4 100644 --- a/lib/Service/AccountService.php +++ b/lib/Service/AccountService.php @@ -258,7 +258,7 @@ class AccountService { // delete related data /** @var PersonInterface $interface */ $interface = AP::$activityPub->getInterfaceFromType(Person::TYPE); - $interface->deleteActor($actor); + $interface->delete($actor); // broadcast delete event $delete = new Delete(); diff --git a/lib/Service/CacheActorService.php b/lib/Service/CacheActorService.php index 387616e5..41807685 100644 --- a/lib/Service/CacheActorService.php +++ b/lib/Service/CacheActorService.php @@ -51,6 +51,7 @@ use OCA\Social\Tools\Exceptions\RequestResultNotJsonException; use OCA\Social\Tools\Exceptions\RequestResultSizeException; use OCA\Social\Tools\Exceptions\RequestServerException; use OCA\Social\Tools\Traits\TArrayTools; +use OCP\AppFramework\Http; use OCP\IURLGenerator; use Psr\Log\LoggerInterface; @@ -132,7 +133,16 @@ class CacheActorService { $actor = $this->cacheActorsRequest->getFromId($id); } catch (CacheActorDoesNotExistException $e) { - $object = $this->curlService->retrieveObject($id); + try { + $object = $this->curlService->retrieveObject($id); + } catch (RequestContentException $e) { + // in case of refresh but remote tells us that actor is gone, we delete it. + if ($refresh && $e->getCode() === Http::STATUS_GONE) { + $this->delete($this->cacheActorsRequest->getFromId($id)); + } + + throw $e; + } $this->logger->debug('object retrieved', ['id' => $id, 'object' => $object]); @@ -304,4 +314,17 @@ class CacheActorService { } catch (ItemUnknownException $e) { } } + + /** + * @param Person $actor + * + * @return void + */ + private function delete(Person $actor): void { + try { + $interface = AP::$activityPub->getInterfaceFromType($actor->getType()); + $interface->delete($actor); + } catch (ItemUnknownException $e) { + } + } } diff --git a/lib/Service/CurlService.php b/lib/Service/CurlService.php index 13c8ca7d..fc770fd9 100644 --- a/lib/Service/CurlService.php +++ b/lib/Service/CurlService.php @@ -247,10 +247,8 @@ class CurlService { $request->setProtocol($url['scheme']); $result = $this->retrieveJson($request); - - if (is_array($result)) { - $result['_host'] = $request->getHost(); - } + $result['_host'] = $request->getHost(); + $result['_resultCode'] = $request->getResultCode(); return $result; }