From: Julius Härtl Date: Tue, 5 Dec 2023 11:31:20 +0000 (+0100) Subject: perf: Only query the db once for trusted servers X-Git-Tag: v29.0.0beta1~705^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F42033%2Fhead;p=nextcloud-server.git perf: Only query the db once for trusted servers Signed-off-by: Julius Härtl --- diff --git a/apps/federation/lib/TrustedServers.php b/apps/federation/lib/TrustedServers.php index c27529bd12c..b110be24aff 100644 --- a/apps/federation/lib/TrustedServers.php +++ b/apps/federation/lib/TrustedServers.php @@ -31,6 +31,7 @@ use OCA\Federation\BackgroundJob\RequestSharedSecret; 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, @@ -122,14 +126,20 @@ class TrustedServers { $server = $this->dbHandler->getServerById($id); $this->dbHandler->removeServer($id); $this->dispatcher->dispatchTyped(new TrustedServerRemovedEvent($server['url_hash'])); + } /** * Get all trusted servers - * @return list + * + * @return list + * @throws Exception */ public function getServers() { - return $this->dbHandler->getAllServer(); + if ($this->trustedServersCache === null) { + $this->trustedServersCache = $this->dbHandler->getAllServer(); + } + return $this->trustedServersCache; } /**