Skip to content

Commit 403a4dc

Browse files
committed
perf: Register notifier and resource listener lazy
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent 2f58f9c commit 403a4dc

2 files changed

Lines changed: 36 additions & 17 deletions

File tree

lib/AppInfo/Application.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
use Closure;
2727
use Exception;
28-
use OC\EventDispatcher\SymfonyAdapter;
2928
use OCA\Circles\Events\CircleDestroyedEvent;
3029
use OCA\Deck\Activity\CommentEventHandler;
3130
use OCA\Deck\Capabilities;
@@ -45,6 +44,7 @@
4544
use OCA\Deck\Listeners\BeforeTemplateRenderedListener;
4645
use OCA\Deck\Listeners\ParticipantCleanupListener;
4746
use OCA\Deck\Listeners\FullTextSearchEventListener;
47+
use OCA\Deck\Listeners\ResourceAdditionalScriptsListener;
4848
use OCA\Deck\Listeners\ResourceListener;
4949
use OCA\Deck\Listeners\LiveUpdateListener;
5050
use OCA\Deck\Middleware\DefaultBoardMiddleware;
@@ -63,15 +63,13 @@
6363
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
6464
use OCP\Collaboration\Reference\RenderReferenceEvent;
6565
use OCP\Collaboration\Resources\IProviderManager;
66+
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent;
6667
use OCP\Comments\CommentsEntityEvent;
6768
use OCP\Comments\ICommentsManager;
6869
use OCP\EventDispatcher\IEventDispatcher;
6970
use OCP\Group\Events\GroupDeletedEvent;
7071
use OCP\IConfig;
7172
use OCP\IDBConnection;
72-
use OCP\IRequest;
73-
use OCP\Server;
74-
use OCP\Notification\IManager as NotificationManager;
7573
use OCP\Share\IManager;
7674
use OCP\User\Events\UserDeletedEvent;
7775
use OCP\Util;
@@ -97,7 +95,6 @@ public function __construct(array $urlParams = []) {
9795
public function boot(IBootContext $context): void {
9896
$context->injectFn(Closure::fromCallable([$this, 'registerCommentsEntity']));
9997
$context->injectFn(Closure::fromCallable([$this, 'registerCommentsEventHandler']));
100-
$context->injectFn(Closure::fromCallable([$this, 'registerNotifications']));
10198
$context->injectFn(Closure::fromCallable([$this, 'registerCollaborationResources']));
10299

103100
$context->injectFn(function (IManager $shareManager) {
@@ -154,10 +151,9 @@ public function register(IRegistrationContext $context): void {
154151
// Event listening for realtime updates via notify_push
155152
$context->registerEventListener(SessionCreatedEvent::class, LiveUpdateListener::class);
156153
$context->registerEventListener(SessionClosedEvent::class, LiveUpdateListener::class);
157-
}
158154

159-
public function registerNotifications(NotificationManager $notificationManager): void {
160-
$notificationManager->registerNotifierService(Notifier::class);
155+
$context->registerNotifierService(Notifier::class);
156+
$context->registerEventListener(LoadAdditionalScriptsEvent::class, ResourceAdditionalScriptsListener::class);
161157
}
162158

163159
public function registerCommentsEntity(IEventDispatcher $eventDispatcher): void {
@@ -183,16 +179,8 @@ protected function registerCommentsEventHandler(ICommentsManager $commentsManage
183179
});
184180
}
185181

186-
protected function registerCollaborationResources(IProviderManager $resourceManager, SymfonyAdapter $symfonyAdapter): void {
182+
protected function registerCollaborationResources(IProviderManager $resourceManager): void {
187183
$resourceManager->registerResourceProvider(ResourceProvider::class);
188184
$resourceManager->registerResourceProvider(ResourceProviderCard::class);
189-
190-
$symfonyAdapter->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', static function () {
191-
if (strpos(Server::get(IRequest::class)->getPathInfo(), '/call/') === 0) {
192-
// Talk integration has its own entrypoint which already includes collections handling
193-
return;
194-
}
195-
Util::addScript('deck', 'deck-collections');
196-
});
197185
}
198186
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace OCA\Deck\Listeners;
4+
5+
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent;
6+
use OCP\EventDispatcher\Event;
7+
use OCP\EventDispatcher\IEventListener;
8+
use OCP\IRequest;
9+
use OCP\Util;
10+
11+
/** @template-implements IEventListener<Event|LoadAdditionalScriptsEvent> */
12+
class ResourceAdditionalScriptsListener implements IEventListener {
13+
private IRequest $request;
14+
15+
public function __construct(IRequest $request) {
16+
$this->request = $request;
17+
}
18+
19+
public function handle(Event $event): void {
20+
if (!$event instanceof LoadAdditionalScriptsEvent) {
21+
return;
22+
}
23+
24+
if (strpos($this->request->getPathInfo(), '/call/') === 0) {
25+
// Talk integration has its own entrypoint which already includes collections handling
26+
return;
27+
}
28+
29+
Util::addScript('deck', 'deck-collections');
30+
}
31+
}

0 commit comments

Comments
 (0)