Merge pull request #23951 from owncloud/cleanlocks-chunk

chunk the cleaning up of shared locks
This commit is contained in:
Thomas Müller 2016-04-20 20:40:32 +02:00
commit 42b25f7821
1 changed files with 18 additions and 7 deletions

View File

@ -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();
}
}
}