From 399643c12170bb8d4f3c7416a40047a6d46d065e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 9 Jun 2026 07:17:59 +0200 Subject: [PATCH] fix(comments): Use capped memory cache for comments Signed-off-by: Joas Schilling --- lib/private/Comments/Manager.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php index 84737897bb4a2..fe39ee48f1df4 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); } /** @@ -1299,7 +1300,7 @@ public function deleteReferencesOfActor($actorType, $actorId): bool { ->setParameter('id', $actorId); $affectedRows = $qb->executeStatement(); - $this->commentsCache = []; + $this->commentsCache->clear(); return true; } @@ -1318,7 +1319,7 @@ public function deleteCommentsAtObject($objectType, $objectId): bool { ->setParameter('id', $objectId); $affectedRows = $qb->executeStatement(); - $this->commentsCache = []; + $this->commentsCache->clear(); return true; } @@ -1568,7 +1569,7 @@ public function deleteCommentsExpiredAtObject(string $objectType, string $object $affectedRows = $qb->executeStatement(); - $this->commentsCache = []; + $this->commentsCache->clear(); return $affectedRows > 0; }