From 03606e53cd4bbdfcd08d8879d209c501147722fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Sat, 16 Dec 2023 10:31:56 +0100 Subject: [PATCH] perf: Avoid re-query of already fetched lock info MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Service/LockService.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Service/LockService.php b/lib/Service/LockService.php index 7adabe9b..6540e24a 100644 --- a/lib/Service/LockService.php +++ b/lib/Service/LockService.php @@ -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) { @@ -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 { @@ -156,6 +157,10 @@ public function getLockForNodeIds(array $nodeIds): array { } } + if (count($expiredLocks) > 0) { + $this->locksRequest->removeIds($expiredLocks); + } + return $locks; }