diff options
author | Vincent Petry <pvince81@owncloud.com> | 2017-03-28 19:18:58 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2017-04-26 13:26:27 +0200 |
commit | e3218ddffda93e1eecd4a307c70f1a8929823f9a (patch) | |
tree | 996e4664026a248fe2a04c9ff9288218bba77ba5 /lib/private/Files/Utils | |
parent | 5b5c3a1773dab4960d41aafc4150859a308311b7 (diff) | |
download | nextcloud-server-e3218ddffda93e1eecd4a307c70f1a8929823f9a.tar.gz nextcloud-server-e3218ddffda93e1eecd4a307c70f1a8929823f9a.zip |
OCC scanner commit in batches
Diffstat (limited to 'lib/private/Files/Utils')
-rw-r--r-- | lib/private/Files/Utils/Scanner.php | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/lib/private/Files/Utils/Scanner.php b/lib/private/Files/Utils/Scanner.php index 02f355fd4d9..a0981beeaba 100644 --- a/lib/private/Files/Utils/Scanner.php +++ b/lib/private/Files/Utils/Scanner.php @@ -47,6 +47,8 @@ use OCP\ILogger; * @package OC\Files\Utils */ class Scanner extends PublicEmitter { + const MAX_ENTRIES_TO_COMMIT = 10000; + /** * @var string $user */ @@ -63,6 +65,20 @@ class Scanner extends PublicEmitter { protected $logger; /** + * Whether to use a DB transaction + * + * @var bool + */ + protected $useTransaction; + + /** + * Number of entries scanned to commit + * + * @var int + */ + protected $entriesToCommit; + + /** * @param string $user * @param \OCP\IDBConnection $db * @param ILogger $logger @@ -71,6 +87,7 @@ class Scanner extends PublicEmitter { $this->logger = $logger; $this->user = $user; $this->db = $db; + $this->useTransaction = !(\OC::$server->getLockingProvider() instanceof DBLockingProvider); } /** @@ -200,22 +217,22 @@ class Scanner extends PublicEmitter { $scanner = $storage->getScanner(); $scanner->setUseTransactions(false); $this->attachListener($mount); - $isDbLocking = \OC::$server->getLockingProvider() instanceof DBLockingProvider; $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { - $this->triggerPropagator($storage, $path); + $this->postProcessEntry($storage, $path); }); $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { - $this->triggerPropagator($storage, $path); + $this->postProcessEntry($storage, $path); }); $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { - $this->triggerPropagator($storage, $path); + $this->postProcessEntry($storage, $path); }); if (!$storage->file_exists($relativePath)) { throw new NotFoundException($dir); } - if (!$isDbLocking) { + + if ($this->useTransaction) { $this->db->beginTransaction(); } try { @@ -233,7 +250,7 @@ class Scanner extends PublicEmitter { $this->logger->logException($e); $this->emit('\OC\Files\Utils\Scanner', 'StorageNotAvailable', [$e]); } - if (!$isDbLocking) { + if ($this->useTransaction) { $this->db->commit(); } } @@ -242,5 +259,20 @@ class Scanner extends PublicEmitter { private function triggerPropagator(IStorage $storage, $internalPath) { $storage->getPropagator()->propagateChange($internalPath, time()); } + + private function postProcessEntry(IStorage $storage, $internalPath) { + $this->triggerPropagator($storage, $internalPath); + $this->entriesToCommit++; + if ($this->useTransaction) { + $propagator = $storage->getPropagator(); + if ($this->entriesToCommit >= self::MAX_ENTRIES_TO_COMMIT) { + $this->entriesToCommit = 0; + $this->db->commit(); + $propagator->commitBatch(); + $this->db->beginTransaction(); + $propagator->beginBatch(); + } + } + } } |