mirror of
https://github.com/nextcloud/server.git
synced 2025-02-26 01:40:18 +00:00
perf: Only query the db once for trusted servers
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
fd06f0c72d
commit
1bff7ccb5c
1 changed files with 12 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue