From f2bc2f7e01aa166faa627df6fe4d5ed4887c16e5 Mon Sep 17 00:00:00 2001 From: Yassine Doghri <yassine@doghri.fr> Date: Wed, 14 Sep 2022 10:21:14 +0000 Subject: [PATCH] fix: overwrite getActorById to return app's Actor entity --- app/Entities/EpisodeComment.php | 2 -- app/Entities/Podcast.php | 2 -- app/Models/ActorModel.php | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/Entities/EpisodeComment.php b/app/Entities/EpisodeComment.php index f2dda34c4c..95deefb49f 100644 --- a/app/Entities/EpisodeComment.php +++ b/app/Entities/EpisodeComment.php @@ -97,12 +97,10 @@ class EpisodeComment extends UuidEntity } if (! $this->actor instanceof Actor) { - // @phpstan-ignore-next-line $this->actor = model(ActorModel::class, false) ->getActorById($this->actor_id); } - // @phpstan-ignore-next-line return $this->actor; } diff --git a/app/Entities/Podcast.php b/app/Entities/Podcast.php index bf1b64b769..7e269bcd71 100644 --- a/app/Entities/Podcast.php +++ b/app/Entities/Podcast.php @@ -207,12 +207,10 @@ class Podcast extends Entity } if (! $this->actor instanceof Actor) { - // @phpstan-ignore-next-line $this->actor = model(ActorModel::class, false) ->getActorById($this->actor_id); } - // @phpstan-ignore-next-line return $this->actor; } diff --git a/app/Models/ActorModel.php b/app/Models/ActorModel.php index 68f24194b3..47b35485d6 100644 --- a/app/Models/ActorModel.php +++ b/app/Models/ActorModel.php @@ -19,4 +19,18 @@ class ActorModel extends FediverseActorModel * @var string */ protected $returnType = Actor::class; + + public function getActorById(int $id): ?Actor + { + $cacheName = config('Fediverse') + ->cachePrefix . "actor#{$id}"; + if (! ($found = cache($cacheName))) { + $found = $this->find($id); + + cache() + ->save($cacheName, $found, DECADE); + } + + return $found; + } } -- GitLab