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

perf: Only query the db once for trusted servers #42033

Merged
merged 1 commit into from
Dec 5, 2023
Merged
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
14 changes: 12 additions & 2 deletions apps/federation/lib/TrustedServers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -122,14 +126,20 @@ public function removeServer(int $id): void {
$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;
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
}

/**
Expand Down
Loading