summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorFaraz Samapoor <fsa@adlas.at>2023-09-26 10:48:17 +0330
committerFaraz Samapoor <fsa@adlas.at>2023-09-26 10:48:17 +0330
commit40d9349a2d5ed7700f35b471f77b709fdcc5a48d (patch)
tree155c00b7df65aa1792d2c288aa48d295ac5bcb91 /lib/private
parent2288e8e57101241724c26d2765875342e14528bc (diff)
downloadnextcloud-server-40d9349a2d5ed7700f35b471f77b709fdcc5a48d.tar.gz
nextcloud-server-40d9349a2d5ed7700f35b471f77b709fdcc5a48d.zip
Refactors lib/private/Lock.
To improve code readability. Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: Faraz Samapoor <f.samapoor@gmail.com> Signed-off-by: Faraz Samapoor <fsa@adlas.at>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Lock/AbstractLockingProvider.php12
-rw-r--r--lib/private/Lock/DBLockingProvider.php14
-rw-r--r--lib/private/Lock/MemcacheLockingProvider.php10
3 files changed, 17 insertions, 19 deletions
diff --git a/lib/private/Lock/AbstractLockingProvider.php b/lib/private/Lock/AbstractLockingProvider.php
index 6e8289db12e..604d098fa65 100644
--- a/lib/private/Lock/AbstractLockingProvider.php
+++ b/lib/private/Lock/AbstractLockingProvider.php
@@ -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) {
diff --git a/lib/private/Lock/DBLockingProvider.php b/lib/private/Lock/DBLockingProvider.php
index fb8af8ac55b..087b1287754 100644
--- a/lib/private/Lock/DBLockingProvider.php
+++ b/lib/private/Lock/DBLockingProvider.php
@@ -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);
}
/**
diff --git a/lib/private/Lock/MemcacheLockingProvider.php b/lib/private/Lock/MemcacheLockingProvider.php
index d4eebd7c302..8ad25576084 100644
--- a/lib/private/Lock/MemcacheLockingProvider.php
+++ b/lib/private/Lock/MemcacheLockingProvider.php
@@ -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 {