summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Müller <DeepDiver1975@users.noreply.github.com>2016-04-20 20:40:32 +0200
committerThomas Müller <DeepDiver1975@users.noreply.github.com>2016-04-20 20:40:32 +0200
commit42b25f78216e55f5ba08eecb2f629128883cf801 (patch)
treee968e00b98a80c729a9b53dc1d7b01869c0c4e92 /lib
parent1ab27ddd4aba5cc74a7264b053378f057bacb8b6 (diff)
parent7b3191705c27c43e62c4459d0ce1f923fd5c2d8e (diff)
downloadnextcloud-server-42b25f78216e55f5ba08eecb2f629128883cf801.tar.gz
nextcloud-server-42b25f78216e55f5ba08eecb2f629128883cf801.zip
Merge pull request #23951 from owncloud/cleanlocks-chunk
chunk the cleaning up of shared locks
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Lock/DBLockingProvider.php25
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/private/Lock/DBLockingProvider.php b/lib/private/Lock/DBLockingProvider.php
index 9e97df44d3f..3a599a61e7d 100644
--- a/lib/private/Lock/DBLockingProvider.php
+++ b/lib/private/Lock/DBLockingProvider.php
@@ -24,7 +24,9 @@
namespace OC\Lock;
+use OC\DB\QueryBuilder\Literal;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\ILogger;
use OCP\Lock\ILockingProvider;
@@ -257,13 +259,22 @@ class DBLockingProvider extends AbstractLockingProvider {
parent::releaseAll();
// since we keep shared locks we need to manually clean those
- foreach ($this->sharedLocks as $path => $lock) {
- if ($lock) {
- $this->connection->executeUpdate(
- 'UPDATE `*PREFIX*file_locks` SET `lock` = `lock` - 1 WHERE `key` = ? AND `lock` > 0',
- [$path]
- );
- }
+ $lockedPaths = array_keys($this->sharedLocks);
+ $lockedPaths = array_filter($lockedPaths, function ($path) {
+ return $this->sharedLocks[$path];
+ });
+
+ $chunkedPaths = array_chunk($lockedPaths, 100);
+
+ foreach ($chunkedPaths as $chunk) {
+ $builder = $this->connection->getQueryBuilder();
+
+ $query = $builder->update('file_locks')
+ ->set('lock', $builder->createFunction('`lock` -1'))
+ ->where($builder->expr()->in('key', $builder->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY)))
+ ->andWhere($builder->expr()->gt('lock', new Literal(0)));
+
+ $query->execute();
}
}
}