Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listen to cache event when deleting metadata #41634

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/private/FilesMetadata/FilesMetadataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
11 changes: 4 additions & 7 deletions lib/private/FilesMetadata/Listener/MetadataDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodeDeletedEvent>
* @template-implements IEventListener<CacheEntryRemovedEvent>
*/
class MetadataDelete implements IEventListener {
public function __construct(
Expand All @@ -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);
}
Expand Down
Loading