From 1d95f4b7cea726a8e58dae835199dbdd0dbd8a97 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Thu, 26 Feb 2026 23:42:44 +0100 Subject: [PATCH] refactor: Port to newer system tag events Signed-off-by: Carl Schwan --- lib/Listener/TagListener.php | 44 ++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/Listener/TagListener.php b/lib/Listener/TagListener.php index 97898a2a9c..5bc9c44337 100644 --- a/lib/Listener/TagListener.php +++ b/lib/Listener/TagListener.php @@ -8,43 +8,47 @@ use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; -use OCP\Files\Config\ICachedMountInfo; use OCP\Files\Config\IUserMountCache; use OCP\Files\IRootFolder; use OCP\ICache; use OCP\ICacheFactory; -use OCP\SystemTag\MapperEvent; +use OCP\SystemTag\TagAssignedEvent; +use OCP\SystemTag\TagUnassignedEvent; +use Override; /** - * @template-implements IEventListener + * @template-implements IEventListener */ class TagListener implements IEventListener { private readonly ICache $tagCountsCache; - private readonly IRootFolder $rootFolder; - private readonly IUserMountCache $userMountCache; - public function __construct(ICacheFactory $cacheFactory, IRootFolder $rootFolder, IUserMountCache $userMountCache) { + public function __construct( + ICacheFactory $cacheFactory, + private readonly IRootFolder $rootFolder, + private readonly IUserMountCache $userMountCache, + ) { $this->tagCountsCache = $cacheFactory->createLocal('photos:tag-counts'); - $this->rootFolder = $rootFolder; - $this->userMountCache = $userMountCache; } - /** - * @inheritDoc - */ + #[Override] public function handle(Event $event): void { - if ($event instanceof MapperEvent) { - if ($event->getObjectType() !== 'files') { - return; - } - $node = $this->rootFolder->getFirstNodeById((int)$event->getObjectId()); + if (!$event instanceof TagAssignedEvent && !$event instanceof TagUnassignedEvent) { + return; + } + + if ($event->getObjectType() !== 'files') { + return; + } + + foreach ($event->getObjectIds() as $objectId) { + $node = $this->rootFolder->getFirstNodeById((int)$objectId); if (!$node) { - return; + continue; } + $mounts = $this->userMountCache->getMountsForRootId($node->getMountPoint()->getStorageRootId()); - $userIds = array_map(static fn (ICachedMountInfo $mount) => $mount->getUser()->getUID(), $mounts); - foreach ($userIds as $userId) { - $this->tagCountsCache->remove($userId); + foreach ($mounts as $mount) { + $this->tagCountsCache->remove($mount->getUser()->getUID()); } } }