Skip to content

Commit

Permalink
Merge pull request #196 from nextcloud/perf/locks-queries
Browse files Browse the repository at this point in the history
perf: Avoid re-query of already fetched lock info
  • Loading branch information
juliusknorr authored Dec 19, 2023
2 parents a16f273 + 36eccf3 commit c55649a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/Service/LockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public function getLockForNodeIds(array $nodeIds): array {
$locks[$nodeId] = $this->lockCache[$nodeId];
} else {
$locksToRequest[] = $nodeId;
$this->lockCache[$nodeId] = false;
}
}
if (count($locksToRequest) === 0) {
Expand All @@ -144,10 +145,10 @@ public function getLockForNodeIds(array $nodeIds): array {
}
$newLocks = array_merge(...$newLocks);

$expiredLocks = [];
foreach ($newLocks as $lock) {
if ($lock->getETA() === 0) {
// TODO batch remove
$this->locksRequest->delete($lock);
$expiredLocks[] = $lock->getId();
$locks[$lock->getFileId()] = false;
$this->lockCache[$lock->getFileId()] = false;
} else {
Expand All @@ -156,6 +157,10 @@ public function getLockForNodeIds(array $nodeIds): array {
}
}

if (count($expiredLocks) > 0) {
$this->locksRequest->removeIds($expiredLocks);
}

return $locks;
}

Expand Down

0 comments on commit c55649a

Please sign in to comment.