diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php index b4922f967e561..45b9134f73f4a 100644 --- a/lib/private/Comments/Manager.php +++ b/lib/private/Comments/Manager.php @@ -8,6 +8,7 @@ namespace OC\Comments; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Cache\CappedMemoryCache; use OCP\Comments\CommentsEvent; use OCP\Comments\Events\BeforeCommentUpdatedEvent; use OCP\Comments\Events\CommentAddedEvent; @@ -33,8 +34,7 @@ use Psr\Log\LoggerInterface; class Manager implements ICommentsManager { - /** @var IComment[] */ - protected array $commentsCache = []; + protected CappedMemoryCache $commentsCache; /** @var \Closure[] */ protected array $eventHandlerClosures = []; @@ -55,6 +55,7 @@ public function __construct( protected IRootFolder $rootFolder, protected IEventDispatcher $eventDispatcher, ) { + $this->commentsCache = new CappedMemoryCache(256); } /** @@ -1322,7 +1323,7 @@ public function deleteReferencesOfActor($actorType, $actorId): bool { ->setParameter('id', $actorId); $affectedRows = $qb->executeStatement(); - $this->commentsCache = []; + $this->commentsCache->clear(); return true; } @@ -1342,7 +1343,7 @@ public function deleteCommentsAtObject($objectType, $objectId): bool { ->setParameter('id', $objectId); $affectedRows = $qb->executeStatement(); - $this->commentsCache = []; + $this->commentsCache->clear(); return true; } @@ -1601,7 +1602,7 @@ public function deleteCommentsExpiredAtObject(string $objectType, string $object $affectedRows = $qb->executeStatement(); - $this->commentsCache = []; + $this->commentsCache->clear(); return $affectedRows > 0; }