Log remote endpoint fetching and time taken

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2022-11-26 09:38:09 +01:00
Родитель 9911a199d8
Коммит 13001c4ec3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4C614C6ED2CDE6DF
2 изменённых файлов: 30 добавлений и 17 удалений

Просмотреть файл

@ -127,7 +127,10 @@ class CapabilitiesService {
}
try {
$startTime = microtime(true);
$response = $client->get($capabilitiesEndpoint, $options);
$duration = round(((microtime(true) - $startTime)), 3);
$this->logger->info('Fetched capabilities endpoint from ' . $capabilitiesEndpoint. ' in ' . $duration . ' seconds');
$responseBody = $response->getBody();
$capabilities = \json_decode($responseBody, true);

Просмотреть файл

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
*
@ -22,30 +25,33 @@
namespace OCA\Richdocuments\WOPI;
use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
use Psr\Log\LoggerInterface;
class DiscoveryManager {
/** @var IClientService */
private $clientService;
/** @var ICache */
private $cache;
/** @var IConfig */
private $config;
private IClientService $clientService;
private ICache $cache;
private IConfig $config;
private LoggerInterface $logger;
/** @var string */
private $discovery;
private ?string $discovery = null;
public function __construct(IClientService $clientService,
public function __construct(
IClientService $clientService,
ICacheFactory $cacheFactory,
IConfig $config) {
IConfig $config,
LoggerInterface $logger
) {
$this->clientService = $clientService;
$this->cache = $cacheFactory->createDistributed('richdocuments');
$this->config = $config;
$this->logger = $logger;
}
public function get() {
public function get(): ?string {
if ($this->discovery) {
return $this->discovery;
}
@ -62,10 +68,9 @@ class DiscoveryManager {
}
/**
* @return \OCP\Http\Client\IResponse
* @throws \Exception
* @throws \Exception if a network error occurs
*/
public function fetchFromRemote() {
public function fetchFromRemote(): IResponse {
$remoteHost = $this->config->getAppValue('richdocuments', 'wopi_url');
$wopiDiscovery = rtrim($remoteHost, '/') . '/hosting/discovery';
@ -80,10 +85,15 @@ class DiscoveryManager {
$options['timeout'] = 180;
}
return $client->get($wopiDiscovery, $options);
$startTime = microtime(true);
$response = $client->get($wopiDiscovery, $options);
$duration = round(((microtime(true) - $startTime)), 3);
$this->logger->info('Fetched discovery endpoint from ' . $wopiDiscovery . ' in ' . $duration . ' seconds');
return $response;
}
public function refetch() {
public function refetch(): void {
$this->cache->remove('discovery');
$this->discovery = null;
}
@ -91,7 +101,7 @@ class DiscoveryManager {
/**
* @return boolean indicating if proxy.php is in initialize or false otherwise
*/
private function isProxyStarting($url) {
private function isProxyStarting(string $url): bool {
$usesProxy = false;
$proxyPos = strrpos($url, 'proxy.php');
if ($proxyPos === false) {