From 71e3f7f8662db3bfb095a4ea966e6e3d3746a861 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Fri, 4 Mar 2016 15:13:56 +0100 Subject: Cache results of testRemoteUrl Otherwise setting up the storage will result in a HTTP request and thus slowing down ownCloud. Replaces https://github.com/owncloud/core/pull/22855 --- apps/files_sharing/lib/external/storage.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/lib/external/storage.php b/apps/files_sharing/lib/external/storage.php index 41f7bef589b..87f5a3598fb 100644 --- a/apps/files_sharing/lib/external/storage.php +++ b/apps/files_sharing/lib/external/storage.php @@ -54,6 +54,11 @@ class Storage extends DAV implements ISharedStorage { */ private $token; + /** + * @var \OCP\ICacheFactory + */ + private $memcacheFactory; + /** * @var \OCP\ICertificateManager */ @@ -67,8 +72,9 @@ class Storage extends DAV implements ISharedStorage { private $manager; public function __construct($options) { + $this->memcacheFactory = \OC::$server->getMemCacheFactory(); $discoveryManager = new DiscoveryManager( - \OC::$server->getMemCacheFactory(), + $this->memcacheFactory, \OC::$server->getHTTPClientService() ); @@ -241,10 +247,21 @@ class Storage extends DAV implements ISharedStorage { } } + /** + * @param string $url + * @return bool + */ private function testRemoteUrl($url) { + $cache = $this->memcacheFactory->create('files_sharing_remote_url'); + if($result = $cache->get($url)) { + return (bool)$result; + } + $result = file_get_contents($url); $data = json_decode($result); - return (is_object($data) and !empty($data->version)); + $returnValue = (is_object($data) and !empty($data->version)); + $cache->set($url, $returnValue); + return $returnValue; } /** -- cgit v1.2.3