Skip to content

Commit

Permalink
Caching of file id, and various small fixes #26655
Browse files Browse the repository at this point in the history
  • Loading branch information
IljaN authored and SergioBertolinSG committed Mar 2, 2017
1 parent fc16c00 commit 7734f0b
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions lib/private/Files/Storage/Wrapper/Checksum.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Icewind\Streams\CallbackWrapper;
use OC\Cache\CappedMemoryCache;
use OC\Files\Stream\Checksum as ChecksumStream;
use OCP\ILogger;

/**
* Class Checksum
Expand All @@ -44,7 +45,6 @@ class Checksum extends Wrapper {
/** File needs to be checksummed on first read because it is already in cache but has no checksum */
const PATH_IN_CACHE_WITHOUT_CHECKSUM = 2;


/** @var array */
private $pathsInCacheWithoutChecksum = [];

Expand All @@ -62,12 +62,11 @@ public function fopen($path, $mode) {
}

// If file is without checksum we save the path and create
// a callback becaause we can only calculate the checksum
// a callback because we can only calculate the checksum
// after the client has read the entire filestream once.
// the checksum is then saved to oc_filecache for subsequent
// retrieval (see onClose())
if ($requirement == self::PATH_IN_CACHE_WITHOUT_CHECKSUM) {
$this->pathsInCacheWithoutChecksum[] = $path;
$checksumStream = \OC\Files\Stream\Checksum::wrap($stream, $path);
return CallbackWrapper::wrap(
$checksumStream,
Expand Down Expand Up @@ -96,12 +95,11 @@ private function getChecksumRequirement($path, $mode) {
// file could be in cache but without checksum for example
// if mounted from ext. storage
$cache = $this->getCache($path);
$cacheEntry = $cache->get($path);

if ($cache->inCache($path)) {
$cacheEntry = $cache->get($path);
if (empty($cacheEntry['checksum'])) {
return self::PATH_IN_CACHE_WITHOUT_CHECKSUM;
}
if ($cacheEntry && empty($cacheEntry['checksum'])) {
$this->pathsInCacheWithoutChecksum[$cacheEntry->getId()] = $path;
return self::PATH_IN_CACHE_WITHOUT_CHECKSUM;
}

return self::NOT_REQUIRED;
Expand All @@ -112,10 +110,9 @@ private function getChecksumRequirement($path, $mode) {
*/
public function onClose() {
$cache = $this->getCache();
foreach ($this->pathsInCacheWithoutChecksum as $path) {
$entry = $cache->get($path);
foreach ($this->pathsInCacheWithoutChecksum as $cacheId => $path) {
$cache->update(
$entry->getId(),
$cacheId,
['checksum' => self::getChecksumsInDbFormat($path)]
);
}
Expand Down

0 comments on commit 7734f0b

Please sign in to comment.