From 7399e8fbc1e0e5b3c7fc6efe65310be61fa60f70 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Thu, 27 Jun 2024 15:15:13 +0200 Subject: [PATCH] Inline filterBookLoans() to bail out early Filter out libraries we don't have permissions to before fetching the related book offers, to reduce the amount of requests some more. --- src/Service/AlmaApi.php | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/src/Service/AlmaApi.php b/src/Service/AlmaApi.php index 57026d1..308813a 100644 --- a/src/Service/AlmaApi.php +++ b/src/Service/AlmaApi.php @@ -625,11 +625,13 @@ public function getBookLoans(array $filters): ArrayCollection if ($library !== null && $libraryCode !== $library->getCode()) { continue; } + // only return the ones the user has permissions to + if (!$this->authorizationService->isLibraryManagerByAlmaId($libraryCode)) { + continue; + } $bookLoans[] = $this->bookLoanFromJsonItem($bookLoanData); } - // only return the ones the user has permissions to - $bookLoans = $this->filterBookLoans($bookLoans); $collection = new ArrayCollection($bookLoans); } elseif ($library) { $this->setAnalyticsUpdateDateHeader(); @@ -1205,27 +1207,6 @@ public function getCurrentPerson(bool $addInternalAttributes): Person return $person; } - /** - * Return book loans where the user has permissions. - * - * @param BookLoan[] $bookLoans - * - * @return BookLoan[] - */ - public function filterBookLoans(array $bookLoans): array - { - $almaLibraryIds = $this->authorizationService->getAlmaLibraryIdsForCurrentUser(); - - $filtered = []; - foreach ($bookLoans as $bookLoan) { - if (in_array($bookLoan->getLibrary(), $almaLibraryIds, true)) { - $filtered[] = $bookLoan; - } - } - - return $filtered; - } - /** * @param array $resumptionData *