aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-10-08 18:28:38 +0200
committerGitHub <noreply@github.com>2018-10-08 18:28:38 +0200
commit2a9e00635531a9b4269c9dc8fc97eeca1e6ce8cf (patch)
treea98413cfec29eaa5e92b2b2f7358f2fcab866d63 /apps/files_external
parent3330600dc5a80a4bbbabbbeafa09523265e2dcd3 (diff)
parent4cbea5f7e123136f081dbe56da7f37cf9b9e41c4 (diff)
downloadnextcloud-server-2a9e00635531a9b4269c9dc8fc97eeca1e6ce8cf.tar.gz
nextcloud-server-2a9e00635531a9b4269c9dc8fc97eeca1e6ce8cf.zip
Merge pull request #11518 from nextcloud/feature/noid/save-s3-requests
S3 reuse information from listObject and skip headObject
Diffstat (limited to 'apps/files_external')
-rw-r--r--apps/files_external/lib/Lib/Storage/AmazonS3.php68
1 files changed, 59 insertions, 9 deletions
diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php
index 097b196b2d4..9d2e0c91099 100644
--- a/apps/files_external/lib/Lib/Storage/AmazonS3.php
+++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php
@@ -61,10 +61,14 @@ class AmazonS3 extends \OC\Files\Storage\Common {
/** @var CappedMemoryCache|Result[] */
private $objectCache;
+ /** @var CappedMemoryCache|array */
+ private $filesCache;
+
public function __construct($parameters) {
parent::__construct($parameters);
$this->parseParams($parameters);
$this->objectCache = new CappedMemoryCache();
+ $this->filesCache = new CappedMemoryCache();
}
/**
@@ -94,6 +98,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
private function clearCache() {
$this->objectCache = new CappedMemoryCache();
+ $this->filesCache = new CappedMemoryCache();
}
private function invalidateCache($key) {
@@ -105,6 +110,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
unset($this->objectCache[$existingKey]);
}
}
+ unset($this->filesCache[$key]);
}
/**
@@ -301,6 +307,12 @@ class AmazonS3 extends \OC\Files\Storage\Common {
isset($object['Key']) ? $object['Key'] : $object['Prefix']
);
$files[] = $file;
+
+ // store this information for later usage
+ $this->filesCache[$file] = [
+ 'ContentLength' => $object['Size'],
+ 'LastModified' => (string)$object['LastModified'],
+ ];
}
}
}
@@ -316,20 +328,14 @@ class AmazonS3 extends \OC\Files\Storage\Common {
$path = $this->normalizePath($path);
try {
- $stat = array();
+ $stat = [];
if ($this->is_dir($path)) {
//folders don't really exist
$stat['size'] = -1; //unknown
$stat['mtime'] = time() - $this->rescanDelay * 1000;
} else {
- $result = $this->headObject($path);
-
- $stat['size'] = $result['ContentLength'] ? $result['ContentLength'] : 0;
- if (isset($result['Metadata']['lastmodified'])) {
- $stat['mtime'] = strtotime($result['Metadata']['lastmodified']);
- } else {
- $stat['mtime'] = strtotime($result['LastModified']);
- }
+ $stat['size'] = $this->getContentLength($path);
+ $stat['mtime'] = strtotime($this->getLastModified($path));
}
$stat['atime'] = time();
@@ -340,6 +346,50 @@ class AmazonS3 extends \OC\Files\Storage\Common {
}
}
+ /**
+ * Return content length for object
+ *
+ * When the information is already present (e.g. opendir has been called before)
+ * this value is return. Otherwise a headObject is emitted.
+ *
+ * @param $path
+ * @return int|mixed
+ */
+ private function getContentLength($path) {
+ if (isset($this->filesCache[$path])) {
+ return $this->filesCache[$path]['ContentLength'];
+ }
+
+ $result = $this->headObject($path);
+ if (isset($result['ContentLength'])) {
+ return $result['ContentLength'];
+ }
+
+ return 0;
+ }
+
+ /**
+ * Return last modified for object
+ *
+ * When the information is already present (e.g. opendir has been called before)
+ * this value is return. Otherwise a headObject is emitted.
+ *
+ * @param $path
+ * @return mixed|string
+ */
+ private function getLastModified($path) {
+ if (isset($this->filesCache[$path])) {
+ return $this->filesCache[$path]['LastModified'];
+ }
+
+ $result = $this->headObject($path);
+ if (isset($result['LastModified'])) {
+ return $result['LastModified'];
+ }
+
+ return 'now';
+ }
+
public function is_dir($path) {
$path = $this->normalizePath($path);
try {