From b63ddc73a27febab7a19353a68c3bdce723d5bba Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Tue, 21 Nov 2023 11:36:41 +0100 Subject: [PATCH] Listen to cache event when deleting metadata Signed-off-by: Louis Chemineau --- lib/private/FilesMetadata/FilesMetadataManager.php | 4 ++-- lib/private/FilesMetadata/Listener/MetadataDelete.php | 11 ++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/private/FilesMetadata/FilesMetadataManager.php b/lib/private/FilesMetadata/FilesMetadataManager.php index 187eed6776834..28498af4ab014 100644 --- a/lib/private/FilesMetadata/FilesMetadataManager.php +++ b/lib/private/FilesMetadata/FilesMetadataManager.php @@ -37,7 +37,7 @@ use OCP\DB\Exception as DBException; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\EventDispatcher\IEventDispatcher; -use OCP\Files\Events\Node\NodeDeletedEvent; +use OCP\Files\Cache\CacheEntryRemovedEvent; use OCP\Files\Events\Node\NodeWrittenEvent; use OCP\Files\InvalidPathException; use OCP\Files\Node; @@ -305,6 +305,6 @@ public function initMetadata( */ public static function loadListeners(IEventDispatcher $eventDispatcher): void { $eventDispatcher->addServiceListener(NodeWrittenEvent::class, MetadataUpdate::class); - $eventDispatcher->addServiceListener(NodeDeletedEvent::class, MetadataDelete::class); + $eventDispatcher->addServiceListener(CacheEntryRemovedEvent::class, MetadataDelete::class); } } diff --git a/lib/private/FilesMetadata/Listener/MetadataDelete.php b/lib/private/FilesMetadata/Listener/MetadataDelete.php index 25c944475a9ee..d950c2cea5f30 100644 --- a/lib/private/FilesMetadata/Listener/MetadataDelete.php +++ b/lib/private/FilesMetadata/Listener/MetadataDelete.php @@ -28,14 +28,14 @@ use Exception; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; -use OCP\Files\Events\Node\NodeDeletedEvent; +use OCP\Files\Cache\CacheEntryRemovedEvent; use OCP\FilesMetadata\IFilesMetadataManager; use Psr\Log\LoggerInterface; /** * Handle file deletion event and remove stored metadata related to the deleted file * - * @template-implements IEventListener + * @template-implements IEventListener */ class MetadataDelete implements IEventListener { public function __construct( @@ -44,16 +44,13 @@ public function __construct( ) { } - /** - * @param Event $event - */ public function handle(Event $event): void { - if (!($event instanceof NodeDeletedEvent)) { + if (!($event instanceof CacheEntryRemovedEvent)) { return; } try { - $nodeId = (int)$event->getNode()->getId(); + $nodeId = $event->getFileId(); if ($nodeId > 0) { $this->filesMetadataManager->deleteMetadata($nodeId); }