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

[stable26] fix(cache): Remove displayname cache entry on delete #40085

Merged
merged 1 commit into from
Sep 5, 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: 4 additions & 0 deletions apps/files_sharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
use OCP\Files\Events\BeforeZipCreatedEvent;
use OCP\Files\IRootFolder;
use OCP\Group\Events\GroupChangedEvent;
use OCP\Group\Events\GroupDeletedEvent;
use OCP\Group\Events\UserAddedEvent;
use OCP\IDBConnection;
use OCP\IGroup;
Expand All @@ -76,6 +77,7 @@
use OCP\Share\Events\ShareCreatedEvent;
use OCP\Share\IManager;
use OCP\User\Events\UserChangedEvent;
use OCP\User\Events\UserDeletedEvent;
use OCP\Util;
use Psr\Container\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Expand Down Expand Up @@ -110,7 +112,9 @@ function () use ($c) {

$context->registerNotifierService(Notifier::class);
$context->registerEventListener(UserChangedEvent::class, DisplayNameCache::class);
$context->registerEventListener(UserDeletedEvent::class, DisplayNameCache::class);
$context->registerEventListener(GroupChangedEvent::class, GroupDisplayNameCache::class);
$context->registerEventListener(GroupDeletedEvent::class, GroupDisplayNameCache::class);
}

public function boot(IBootContext $context): void {
Expand Down
6 changes: 6 additions & 0 deletions lib/private/Group/DisplayNameCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Group\Events\GroupChangedEvent;
use OCP\Group\Events\GroupDeletedEvent;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IGroupManager;
Expand Down Expand Up @@ -83,5 +84,10 @@ public function handle(Event $event): void {
$this->cache[$groupId] = $newDisplayName;
$this->memCache->set($groupId, $newDisplayName, 60 * 10); // 10 minutes
}
if ($event instanceof GroupDeletedEvent) {
$groupId = $event->getGroup()->getGID();
unset($this->cache[$groupId]);
$this->memCache->remove($groupId);
}
}
}
6 changes: 6 additions & 0 deletions lib/private/User/DisplayNameCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCP\ICacheFactory;
use OCP\IUserManager;
use OCP\User\Events\UserChangedEvent;
use OCP\User\Events\UserDeletedEvent;

/**
* Class that cache the relation UserId -> Display name
Expand Down Expand Up @@ -81,5 +82,10 @@ public function handle(Event $event): void {
$this->cache[$userId] = $newDisplayName;
$this->memCache->set($userId, $newDisplayName, 60 * 10); // 10 minutes
}
if ($event instanceof UserDeletedEvent) {
$userId = $event->getUser()->getUID();
unset($this->cache[$userId]);
$this->memCache->remove($userId);
}
}
}
Loading