From 33fdca1133244d2ff581561996baa999e572bf33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 5 Dec 2023 12:31:20 +0100 Subject: [PATCH] perf: Only query the db once for trusted servers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/federation/lib/TrustedServers.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/federation/lib/TrustedServers.php b/apps/federation/lib/TrustedServers.php index c27529bd12cb6..4295d4c4df297 100644 --- a/apps/federation/lib/TrustedServers.php +++ b/apps/federation/lib/TrustedServers.php @@ -31,6 +31,7 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; +use OCP\DB\Exception; use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\Events\TrustedServerRemovedEvent; use OCP\HintException; @@ -59,6 +60,9 @@ class TrustedServers { private IEventDispatcher $dispatcher; private ITimeFactory $timeFactory; + /** @var list|null */ + private ?array $trustedServersCache = null; + public function __construct( DbHandler $dbHandler, IClientService $httpClientService, @@ -126,10 +130,15 @@ public function removeServer(int $id): void { /** * Get all trusted servers + * * @return list - */ + * @throws Exception +*/ public function getServers() { - return $this->dbHandler->getAllServer(); + if ($this->trustedServersCache === null) { + $this->trustedServersCache = $this->dbHandler->getAllServer(); + } + return $this->trustedServersCache; } /**