mirror of
https://github.com/nextcloud/server.git
synced 2026-06-12 18:21:40 -04:00
Merge pull request #39108 from fsamapoor/refactor_lib_private_lock
Refactors lib/private/Lock
This commit is contained in:
commit
740b38be2b
3 changed files with 17 additions and 19 deletions
|
|
@ -33,14 +33,18 @@ use OCP\Lock\ILockingProvider;
|
|||
* to release any leftover locks at the end of the request
|
||||
*/
|
||||
abstract class AbstractLockingProvider implements ILockingProvider {
|
||||
/** how long until we clear stray locks in seconds */
|
||||
protected int $ttl;
|
||||
|
||||
protected $acquiredLocks = [
|
||||
protected array $acquiredLocks = [
|
||||
'shared' => [],
|
||||
'exclusive' => []
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $ttl how long until we clear stray locks in seconds
|
||||
*/
|
||||
public function __construct(protected int $ttl) {
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
protected function hasAcquiredLock(string $path, int $type): bool {
|
||||
if ($type === self::LOCK_SHARED) {
|
||||
|
|
|
|||
|
|
@ -39,21 +39,15 @@ use OCP\Lock\LockedException;
|
|||
* Locking provider that stores the locks in the database
|
||||
*/
|
||||
class DBLockingProvider extends AbstractLockingProvider {
|
||||
private IDBConnection $connection;
|
||||
private ITimeFactory $timeFactory;
|
||||
private array $sharedLocks = [];
|
||||
private bool $cacheSharedLocks;
|
||||
|
||||
public function __construct(
|
||||
IDBConnection $connection,
|
||||
ITimeFactory $timeFactory,
|
||||
private IDBConnection $connection,
|
||||
private ITimeFactory $timeFactory,
|
||||
int $ttl = 3600,
|
||||
bool $cacheSharedLocks = true
|
||||
private bool $cacheSharedLocks = true
|
||||
) {
|
||||
$this->connection = $connection;
|
||||
$this->timeFactory = $timeFactory;
|
||||
$this->ttl = $ttl;
|
||||
$this->cacheSharedLocks = $cacheSharedLocks;
|
||||
parent::__construct($ttl);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -32,11 +32,11 @@ use OCP\IMemcacheTTL;
|
|||
use OCP\Lock\LockedException;
|
||||
|
||||
class MemcacheLockingProvider extends AbstractLockingProvider {
|
||||
private IMemcache $memcache;
|
||||
|
||||
public function __construct(IMemcache $memcache, int $ttl = 3600) {
|
||||
$this->memcache = $memcache;
|
||||
$this->ttl = $ttl;
|
||||
public function __construct(
|
||||
private IMemcache $memcache,
|
||||
int $ttl = 3600,
|
||||
) {
|
||||
parent::__construct($ttl);
|
||||
}
|
||||
|
||||
private function setTTL(string $path): void {
|
||||
|
|
|
|||
Loading…
Reference in a new issue