Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions lib/Service/LockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
private array $locks = [];
private bool $lockRetrieved = false;
private array $lockCache = [];
private array $remoteLockCache = [];
private ?array $directEditors = null;
private bool $allowUserOverride = false;

Expand All @@ -70,7 +71,7 @@
IUserSession $userSession,
IRequest $request,
LoggerInterface $logger,
private IRootFolder $rootFolder,

Check failure on line 74 in lib/Service/LockService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

MissingDependency

lib/Service/LockService.php:74:3: MissingDependency: OCP\Files\IRootFolder depends on class or interface oc\hooks\emitter that does not exist (see https://psalm.dev/157)
) {
$this->l10n = $l10n;
$this->userManager = $userManager;
Expand All @@ -90,18 +91,26 @@
* @return FileLock|bool
*/
public function getLockForNodeId(int $nodeId, ?Node $node = null) {
if (array_key_exists($nodeId, $this->lockCache) && $this->lockCache[$nodeId] !== null) {
if (array_key_exists($nodeId, $this->lockCache) && $this->lockCache[$nodeId] !== false) {
return $this->lockCache[$nodeId];
}

try {
$this->lockCache[$nodeId] = $this->getLockFromFileId($nodeId);
} catch (LockNotFoundException) {
$remoteLock = $this->getRemoteLockFromDav($nodeId, $node);
$this->lockCache[$nodeId] = $remoteLock ?: false;
if (array_key_exists($nodeId, $this->remoteLockCache)) {
return $this->remoteLockCache[$nodeId];
}

if (!array_key_exists($nodeId, $this->lockCache)) {
try {
$this->lockCache[$nodeId] = $this->getLockFromFileId($nodeId);
return $this->lockCache[$nodeId];
} catch (LockNotFoundException) {
$this->lockCache[$nodeId] = false;
}
}

return $this->lockCache[$nodeId];
$remoteLock = $this->getRemoteLockFromDav($nodeId, $node);
$this->remoteLockCache[$nodeId] = $remoteLock ?: false;
return $this->remoteLockCache[$nodeId];
}

/**
Expand All @@ -113,8 +122,10 @@
$locks = [];
$locksToRequest = [];
foreach ($nodeIds as $nodeId) {
if (array_key_exists($nodeId, $this->lockCache) && $this->lockCache[$nodeId] !== null) {
if (array_key_exists($nodeId, $this->lockCache) && $this->lockCache[$nodeId] instanceof FileLock) {
$locks[$nodeId] = $this->lockCache[$nodeId];
} elseif (array_key_exists($nodeId, $this->remoteLockCache)) {
$locks[$nodeId] = $this->remoteLockCache[$nodeId];
} else {
$locksToRequest[] = $nodeId;
}
Expand All @@ -123,6 +134,12 @@
return $locks;
}

// pre-fill the cache with negative hits for all requested ids
// so if no lock is found for the file we store the negative hit
foreach ($locksToRequest as $fileId) {
$this->lockCache[$fileId] = false;
}

$newLocks = [];
while ($fileIds = array_splice($locksToRequest, 0, 1000)) {
$newLocks[] = $this->locksRequest->getFromFileIds($fileIds);
Expand Down Expand Up @@ -408,7 +425,7 @@
}

if (!$node) {
$userFolder = $this->rootFolder->getUserFolder($user->getUID());

Check failure on line 428 in lib/Service/LockService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

MissingDependency

lib/Service/LockService.php:428:19: MissingDependency: OCP\Files\IRootFolder depends on class or interface oc\hooks\emitter that does not exist (see https://psalm.dev/157)
$node = $userFolder->getFirstNodeById($nodeId);
}
if (empty($node)) {
Expand Down
Loading