]> source.dussan.org Git - nextcloud-server.git/commitdiff
Refactors lib/private/Lock. 39108/head
authorFaraz Samapoor <fsa@adlas.at>
Tue, 26 Sep 2023 07:18:17 +0000 (10:48 +0330)
committerFaraz Samapoor <fsa@adlas.at>
Tue, 26 Sep 2023 07:18:17 +0000 (10:48 +0330)
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>
lib/private/Lock/AbstractLockingProvider.php
lib/private/Lock/DBLockingProvider.php
lib/private/Lock/MemcacheLockingProvider.php

index 6e8289db12eea9eb4d6af298340d5a622545287b..604d098fa65c1e3156959972f0a9aa0c5af1e24e 100644 (file)
@@ -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) {
index fb8af8ac55bd041e1d01bcf0864b79dda06d4d19..087b12877543f190244491b2bfee20828e899b71 100644 (file)
@@ -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);
        }
 
        /**
index d4eebd7c3022175e6be8ee722fdf564dc436f9e5..8ad25576084a5e1c464f70f8de29d6eea85de0a4 100644 (file)
@@ -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 {