summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-09-23 10:59:58 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-09-23 10:59:58 +0200
commitf3d60df56dec22d2f2f39920c0a93913a9040dad (patch)
tree083437e86bff5bce2124d0e421e58e1f57e1b101
parentc22b98b05ed81c6a2615e6002ae91800b4127ec5 (diff)
parent5f11049852faaff2fffc69c7d59ba50c9482190c (diff)
downloadnextcloud-server-f3d60df56dec22d2f2f39920c0a93913a9040dad.tar.gz
nextcloud-server-f3d60df56dec22d2f2f39920c0a93913a9040dad.zip
Merge pull request #19267 from owncloud/individual-it-reduce_db_calls_for_filelocks
[jenkins] Individual it reduce db calls for filelocks
-rw-r--r--lib/private/lock/dblockingprovider.php36
1 files changed, 24 insertions, 12 deletions
diff --git a/lib/private/lock/dblockingprovider.php b/lib/private/lock/dblockingprovider.php
index bfa86a6920e..a08357a6024 100644
--- a/lib/private/lock/dblockingprovider.php
+++ b/lib/private/lock/dblockingprovider.php
@@ -58,9 +58,17 @@ class DBLockingProvider extends AbstractLockingProvider {
$this->timeFactory = $timeFactory;
}
- protected function initLockField($path) {
+ /**
+ * Insert a file locking row if it does not exists.
+ *
+ * @param string $path
+ * @param int $lock
+ * @return int number of inserted rows
+ */
+
+ protected function initLockField($path, $lock = 0) {
$expire = $this->getExpireTime();
- $this->connection->insertIfNotExist('*PREFIX*file_locks', ['key' => $path, 'lock' => 0, 'ttl' => $expire], ['key']);
+ return $this->connection->insertIfNotExist('*PREFIX*file_locks', ['key' => $path, 'lock' => $lock, 'ttl' => $expire], ['key']);
}
/**
@@ -98,18 +106,23 @@ class DBLockingProvider extends AbstractLockingProvider {
$this->logger->warning("Trying to acquire a lock for '$path' while inside a transition");
}
- $this->initLockField($path);
$expire = $this->getExpireTime();
if ($type === self::LOCK_SHARED) {
- $result = $this->connection->executeUpdate(
- 'UPDATE `*PREFIX*file_locks` SET `lock` = `lock` + 1, `ttl` = ? WHERE `key` = ? AND `lock` >= 0',
- [$expire, $path]
- );
+ $result = $this->initLockField($path,1);
+ if ($result <= 0) {
+ $result = $this->connection->executeUpdate (
+ 'UPDATE `*PREFIX*file_locks` SET `lock` = `lock` + 1, `ttl` = ? WHERE `key` = ? AND `lock` >= 0',
+ [$expire, $path]
+ );
+ }
} else {
- $result = $this->connection->executeUpdate(
- 'UPDATE `*PREFIX*file_locks` SET `lock` = -1, `ttl` = ? WHERE `key` = ? AND `lock` = 0',
- [$expire, $path]
- );
+ $result = $this->initLockField($path,-1);
+ if ($result <= 0) {
+ $result = $this->connection->executeUpdate(
+ 'UPDATE `*PREFIX*file_locks` SET `lock` = -1, `ttl` = ? WHERE `key` = ? AND `lock` = 0',
+ [$expire, $path]
+ );
+ }
}
if ($result !== 1) {
throw new LockedException($path);
@@ -122,7 +135,6 @@ class DBLockingProvider extends AbstractLockingProvider {
* @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
*/
public function releaseLock($path, $type) {
- $this->initLockField($path);
if ($type === self::LOCK_SHARED) {
$this->connection->executeUpdate(
'UPDATE `*PREFIX*file_locks` SET `lock` = `lock` - 1 WHERE `key` = ? AND `lock` > 0',