From df16a0c5e3f060d15b4ebc1df6264cc207aee043 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 18 Jul 2016 11:35:14 +0200 Subject: [PATCH] Store the shared propagator instance This instead of recreating it for every call. --- apps/files_sharing/lib/sharedstorage.php | 7 ++++++- lib/private/Files/Utils/Scanner.php | 10 ++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 4b3f4b0795dc..2c5d4bab7922 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -328,10 +328,15 @@ public function getScanner($path = '', $storage = null) { } public function getPropagator($storage = null) { + if (isset($this->propagator)) { + return $this->propagator; + } + if (!$storage) { $storage = $this; } - return new \OCA\Files_Sharing\SharedPropagator($storage, \OC::$server->getDatabaseConnection()); + $this->propagator = new \OCA\Files_Sharing\SharedPropagator($storage, \OC::$server->getDatabaseConnection()); + return $this->propagator; } public function getOwner($path) { diff --git a/lib/private/Files/Utils/Scanner.php b/lib/private/Files/Utils/Scanner.php index e4e5e353f9f5..0fbe0967877c 100644 --- a/lib/private/Files/Utils/Scanner.php +++ b/lib/private/Files/Utils/Scanner.php @@ -138,9 +138,10 @@ public function backgroundScan($dir) { $this->triggerPropagator($storage, $path); }); - $storage->getPropagator()->beginBatch(); + $propagator = $storage->getPropagator(); + $propagator->beginBatch(); $scanner->backgroundScan(); - $storage->getPropagator()->commitBatch(); + $propagator->commitBatch(); } } @@ -189,14 +190,15 @@ public function scan($dir = '') { $this->db->beginTransaction(); } try { - $storage->getPropagator()->beginBatch(); + $propagator = $storage->getPropagator(); + $propagator->beginBatch(); $scanner->scan($relativePath, \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE); $cache = $storage->getCache(); if ($cache instanceof Cache) { // only re-calculate for the root folder we scanned, anything below that is taken care of by the scanner $cache->correctFolderSize($relativePath); } - $storage->getPropagator()->commitBatch(); + $propagator->commitBatch(); } catch (StorageNotAvailableException $e) { $this->logger->error('Storage ' . $storage->getId() . ' not available'); $this->logger->logException($e);