diff --git a/app/Entities/EpisodeComment.php b/app/Entities/EpisodeComment.php index f2dda34c4cc1251e7672cb84749018ff8a3e0367..95deefb49f066d256666e3a59e1eff73c7a3d655 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 bf1b64b7690990bd5532d135cf3fa468be265738..7e269bcd71f72b105f084c9b1fa91ee84f21485a 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 68f24194b352fdfdeb65eafa6956adea9d05c8f2..47b35485d6cf54d46f367741412d4f1b714a238d 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; + } }