]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use bigger transactions when doing explicit file system scans
authorRobin Appelman <icewind@owncloud.com>
Sun, 7 Sep 2014 23:34:03 +0000 (01:34 +0200)
committerRobin Appelman <icewind@owncloud.com>
Mon, 8 Sep 2014 12:15:41 +0000 (14:15 +0200)
apps/files/ajax/scan.php
apps/files/command/scan.php
lib/private/files/cache/scanner.php
lib/private/files/utils/scanner.php
tests/lib/files/etagtest.php

index 3ec7f9394b115e2d1a29be20e47a2f41de4b5a49..43760cc4196188f35dee266fc0c1a2c40bc4408b 100644 (file)
@@ -20,7 +20,7 @@ $listener = new ScanListener($eventSource);
 
 foreach ($users as $user) {
        $eventSource->send('user', $user);
-       $scanner = new \OC\Files\Utils\Scanner($user);
+       $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection());
        $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', array($listener, 'file'));
        $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', array($listener, 'folder'));
        if ($force) {
index 3412cf80dea2ff6cf6024b0feed1da66b139c3f9..e4d719a8b4be93623cd3081a43566b9a0e53f782 100644 (file)
@@ -46,7 +46,7 @@ class Scan extends Command {
        }
 
        protected function scanFiles($user, OutputInterface $output) {
-               $scanner = new \OC\Files\Utils\Scanner($user);
+               $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection());
                $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) {
                        $output->writeln("Scanning <info>$path</info>");
                });
index 2d87871fd89b09cf2c09088f2f2b4f3b44f0fee6..cca4f289c809adb34fe73a2249c29c8806422ec3 100644 (file)
@@ -44,6 +44,11 @@ class Scanner extends BasicEmitter {
         */
        protected $cacheActive;
 
+       /**
+        * @var bool $transactions whether to use transactions
+        */
+       protected $useTransactions = true;
+
        const SCAN_RECURSIVE = true;
        const SCAN_SHALLOW = false;
 
@@ -57,6 +62,16 @@ class Scanner extends BasicEmitter {
                $this->cacheActive = !Config::getSystemValue('filesystem_cache_readonly', false);
        }
 
+       /**
+        * Whether to wrap the scanning of a folder in a database transaction
+        * On default transactions are used
+        *
+        * @param bool $useTransactions
+        */
+       public function setUseTransactions($useTransactions) {
+               $this->useTransactions = $useTransactions;
+       }
+
        /**
         * get all the metadata of a file or folder
         * *
@@ -234,7 +249,9 @@ class Scanner extends BasicEmitter {
                $newChildren = array();
                if ($this->storage->is_dir($path) && ($dh = $this->storage->opendir($path))) {
                        $exceptionOccurred = false;
-                       \OC_DB::beginTransaction();
+                       if ($this->useTransactions) {
+                               \OC_DB::beginTransaction();
+                       }
                        if (is_resource($dh)) {
                                while (($file = readdir($dh)) !== false) {
                                        $child = ($path) ? $path . '/' . $file : $file;
@@ -266,7 +283,9 @@ class Scanner extends BasicEmitter {
                                $child = ($path) ? $path . '/' . $childName : $childName;
                                $this->removeFromCache($child);
                        }
-                       \OC_DB::commit();
+                       if ($this->useTransactions) {
+                               \OC_DB::commit();
+                       }
                        if ($exceptionOccurred) {
                                // It might happen that the parallel scan process has already
                                // inserted mimetypes but those weren't available yet inside the transaction
index c2fabf519464b23ee91cb62afb4f8a53323ec59f..c7da4505af5692683efca9e386fb5d4134887c80 100644 (file)
@@ -34,12 +34,19 @@ class Scanner extends PublicEmitter {
         */
        protected $propagator;
 
+       /**
+        * @var \OCP\IDBConnection
+        */
+       protected $db;
+
        /**
         * @param string $user
+        * @param \OCP\IDBConnection $db
         */
-       public function __construct($user) {
+       public function __construct($user, $db) {
                $this->user = $user;
                $this->propagator = new ChangePropagator(new View(''));
+               $this->db = $db;
        }
 
        /**
@@ -121,8 +128,11 @@ class Scanner extends PublicEmitter {
                                throw new ForbiddenException();
                        }
                        $scanner = $storage->getScanner();
+                       $scanner->useTransactions(false);
                        $this->attachListener($mount);
+                       $this->db->beginTransaction();
                        $scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE);
+                       $this->db->commit();
                }
                $this->propagator->propagateChanges(time());
        }
index af9f66835f091ce3b6a296c658f6784d82911f27..b5dec107e795fe2e660c9dce50f898c439547e55 100644 (file)
@@ -62,7 +62,7 @@ class EtagTest extends \PHPUnit_Framework_TestCase {
                $files = array('/foo.txt', '/folder/bar.txt', '/folder/subfolder', '/folder/subfolder/qwerty.txt');
                $originalEtags = $this->getEtags($files);
 
-               $scanner = new \OC\Files\Utils\Scanner($user1);
+               $scanner = new \OC\Files\Utils\Scanner($user1, \OC::$server->getDatabaseConnection());
                $scanner->backgroundScan('/');
 
                $newEtags = $this->getEtags($files);