summaryrefslogtreecommitdiffstats
path: root/lib/private/files
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2014-09-09 23:32:32 +0200
committerLukas Reschke <lukas@owncloud.com>2014-09-09 23:32:32 +0200
commitc3d90b96c8ec4bcf96e28c6ccdb194494888cc61 (patch)
tree8b394cd232420042ea85ac8fde6f6ba878942f84 /lib/private/files
parentcd94b54be3676a2be772ef76c39ad706ff3eb947 (diff)
parentfa718d2e2cccb8e48b89044166a80b82b91288fa (diff)
downloadnextcloud-server-c3d90b96c8ec4bcf96e28c6ccdb194494888cc61.tar.gz
nextcloud-server-c3d90b96c8ec4bcf96e28c6ccdb194494888cc61.zip
Merge pull request #10922 from owncloud/explicit-scan-transactions
Use bigger transactions when doing explicit file system scans
Diffstat (limited to 'lib/private/files')
-rw-r--r--lib/private/files/cache/scanner.php23
-rw-r--r--lib/private/files/utils/scanner.php12
2 files changed, 32 insertions, 3 deletions
diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php
index 2d87871fd89..dfba2d920a0 100644
--- a/lib/private/files/cache/scanner.php
+++ b/lib/private/files/cache/scanner.php
@@ -44,6 +44,11 @@ class Scanner extends BasicEmitter {
*/
protected $cacheActive;
+ /**
+ * @var bool $useTransactions whether to use transactions
+ */
+ protected $useTransactions = true;
+
const SCAN_RECURSIVE = true;
const SCAN_SHALLOW = false;
@@ -58,6 +63,16 @@ class Scanner extends BasicEmitter {
}
/**
+ * 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
diff --git a/lib/private/files/utils/scanner.php b/lib/private/files/utils/scanner.php
index c2fabf51946..c7da4505af5 100644
--- a/lib/private/files/utils/scanner.php
+++ b/lib/private/files/utils/scanner.php
@@ -35,11 +35,18 @@ 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());
}