Przeglądaj źródła

Merge pull request #11518 from nextcloud/feature/noid/save-s3-requests

S3 reuse information from listObject and skip headObject
tags/v15.0.0beta1
Morris Jobke 5 lat temu
rodzic
commit
2a9e006355
No account linked to committer's email address
1 zmienionych plików z 59 dodań i 9 usunięć
  1. 59
    9
      apps/files_external/lib/Lib/Storage/AmazonS3.php

+ 59
- 9
apps/files_external/lib/Lib/Storage/AmazonS3.php Wyświetl plik

/** @var CappedMemoryCache|Result[] */ /** @var CappedMemoryCache|Result[] */
private $objectCache; private $objectCache;


/** @var CappedMemoryCache|array */
private $filesCache;

public function __construct($parameters) { public function __construct($parameters) {
parent::__construct($parameters); parent::__construct($parameters);
$this->parseParams($parameters); $this->parseParams($parameters);
$this->objectCache = new CappedMemoryCache(); $this->objectCache = new CappedMemoryCache();
$this->filesCache = new CappedMemoryCache();
} }


/** /**


private function clearCache() { private function clearCache() {
$this->objectCache = new CappedMemoryCache(); $this->objectCache = new CappedMemoryCache();
$this->filesCache = new CappedMemoryCache();
} }


private function invalidateCache($key) { private function invalidateCache($key) {
unset($this->objectCache[$existingKey]); unset($this->objectCache[$existingKey]);
} }
} }
unset($this->filesCache[$key]);
} }


/** /**
isset($object['Key']) ? $object['Key'] : $object['Prefix'] isset($object['Key']) ? $object['Key'] : $object['Prefix']
); );
$files[] = $file; $files[] = $file;

// store this information for later usage
$this->filesCache[$file] = [
'ContentLength' => $object['Size'],
'LastModified' => (string)$object['LastModified'],
];
} }
} }
} }
$path = $this->normalizePath($path); $path = $this->normalizePath($path);


try { try {
$stat = array();
$stat = [];
if ($this->is_dir($path)) { if ($this->is_dir($path)) {
//folders don't really exist //folders don't really exist
$stat['size'] = -1; //unknown $stat['size'] = -1; //unknown
$stat['mtime'] = time() - $this->rescanDelay * 1000; $stat['mtime'] = time() - $this->rescanDelay * 1000;
} else { } 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(); $stat['atime'] = time();


} }
} }


/**
* 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) { public function is_dir($path) {
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
try { try {

Ładowanie…
Anuluj
Zapisz