aboutsummaryrefslogtreecommitdiffstats
path: root/apps/federation
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2023-12-05 12:31:20 +0100
committerJulius Härtl <jus@bitgrid.net>2023-12-05 16:55:02 +0100
commit1bff7ccb5ce7a67f28f0fda0ef72179e32462fb5 (patch)
tree3734654f7e62dda09744734452675d3a4bd7e418 /apps/federation
parentfd06f0c72de958855d535230b79583b30b9763b1 (diff)
downloadnextcloud-server-1bff7ccb5ce7a67f28f0fda0ef72179e32462fb5.tar.gz
nextcloud-server-1bff7ccb5ce7a67f28f0fda0ef72179e32462fb5.zip
perf: Only query the db once for trusted servers
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/federation')
-rw-r--r--apps/federation/lib/TrustedServers.php14
1 files changed, 12 insertions, 2 deletions
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<array{id: int, url: string, url_hash: string, shared_secret: ?string, status: int, sync_token: ?string}>|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<array{id: int, url: string, url_hash: string, shared_secret: string, status: int, sync_token: string}>
+ *
+ * @return list<array{id: int, url: string, url_hash: string, shared_secret: ?string, status: int, sync_token: ?string}>
+ * @throws Exception
*/
public function getServers() {
- return $this->dbHandler->getAllServer();
+ if ($this->trustedServersCache === null) {
+ $this->trustedServersCache = $this->dbHandler->getAllServer();
+ }
+ return $this->trustedServersCache;
}
/**