Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/richdocuments.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2020-11-06 12:54:41 +0300
committerJulius Härtl <jus@bitgrid.net>2020-11-08 12:08:50 +0300
commit6b3d3f155698ac72e21f3046e1cd278439a98adb (patch)
tree738110ba3c06191c24981b4a20d4e8706f8e8d6c /lib
parent74bdf6d216060da02b6764e4de91b9db09c24fb8 (diff)
Store discovery response in distributed cache
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/Command/ActivateConfig.php2
-rw-r--r--lib/Controller/SettingsController.php2
-rw-r--r--lib/WOPI/DiscoveryManager.php74
3 files changed, 26 insertions, 52 deletions
diff --git a/lib/Command/ActivateConfig.php b/lib/Command/ActivateConfig.php
index 793d9fde..68413521 100644
--- a/lib/Command/ActivateConfig.php
+++ b/lib/Command/ActivateConfig.php
@@ -65,7 +65,7 @@ class ActivateConfig extends Command {
protected function execute(InputInterface $input, OutputInterface $output) {
try {
- $this->discoveryManager->refretch();
+ $this->discoveryManager->refetch();
$this->capabilitiesService->clear();
$capaUrlSrc = $this->wopiParser->getUrlSrc('Capabilities');
if (is_array($capaUrlSrc) && $capaUrlSrc['action'] === 'getinfo') {
diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php
index 2b649eaf..e5a45dd8 100644
--- a/lib/Controller/SettingsController.php
+++ b/lib/Controller/SettingsController.php
@@ -169,7 +169,7 @@ class SettingsController extends Controller{
$this->appConfig->setAppValue('canonical_webroot', $canonical_webroot);
}
- $this->discoveryManager->refretch();
+ $this->discoveryManager->refetch();
$this->capabilitiesService->clear();
try {
$capaUrlSrc = $this->wopiParser->getUrlSrc('Capabilities');
diff --git a/lib/WOPI/DiscoveryManager.php b/lib/WOPI/DiscoveryManager.php
index 8c6075cc..585a0c76 100644
--- a/lib/WOPI/DiscoveryManager.php
+++ b/lib/WOPI/DiscoveryManager.php
@@ -21,70 +21,45 @@
namespace OCA\Richdocuments\WOPI;
-use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\Files\IAppData;
-use OCP\Files\NotFoundException;
-use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\Http\Client\IClientService;
+use OCP\ICache;
+use OCP\ICacheFactory;
use OCP\IConfig;
-use OCP\IL10N;
class DiscoveryManager {
+
/** @var IClientService */
private $clientService;
- /** @var ISimpleFolder */
- private $appData;
+ /** @var ICache */
+ private $cache;
/** @var IConfig */
private $config;
- /** @var IL10N */
- private $l10n;
- /** @var ITimeFactory */
- private $timeFactory;
- /**
- * @param IClientService $clientService
- * @param IAppData $appData
- * @param IConfig $config
- * @param IL10N $l10n
- * @param ITimeFactory $timeFactory
- */
+ /** @var string */
+ private $discovery;
+
public function __construct(IClientService $clientService,
- IAppData $appData,
- IConfig $config,
- IL10N $l10n,
- ITimeFactory $timeFactory) {
+ ICacheFactory $cacheFactory,
+ IConfig $config) {
$this->clientService = $clientService;
- try {
- $this->appData = $appData->getFolder('richdocuments');
- } catch (NotFoundException $e) {
- $this->appData = $appData->newFolder('richdocuments');
- }
+ $this->cache = $cacheFactory->createDistributed('richdocuments');
$this->config = $config;
- $this->timeFactory = $timeFactory;
}
public function get() {
- // First check if there is a local valid discovery file
- try {
- $file = $this->appData->getFile('discovery.xml');
- $decodedFile = json_decode($file->getContent(), true);
- if($decodedFile['timestamp'] + 3600 > $this->timeFactory->getTime()) {
- return $decodedFile['data'];
- }
- } catch (NotFoundException $e) {
- $file = $this->appData->newFile('discovery.xml');
+ if ($this->discovery) {
+ return $this->discovery;
}
- $response = $this->fetchFromRemote();
+ $this->discovery = $this->cache->get('discovery');
+ if (!$this->discovery) {
+ $response = $this->fetchFromRemote();
+ $responseBody = $response->getBody();
+ $this->discovery = $responseBody;
+ $this->cache->set('discovery', $this->discovery, 3600);
+ }
- $responseBody = $response->getBody();
- $file->putContent(
- json_encode([
- 'data' => $responseBody,
- 'timestamp' => $this->timeFactory->getTime(),
- ])
- );
- return $responseBody;
+ return $this->discovery;
}
/**
@@ -109,9 +84,8 @@ class DiscoveryManager {
}
}
- public function refretch() {
- try {
- $this->appData->getFile('discovery.xml')->delete();
- } catch(\Exception $e) {}
+ public function refetch() {
+ $this->cache->remove('discovery');
+ $this->discovery = null;
}
}