Skip to content

Commit

Permalink
Inline filterBookLoans() to bail out early
Browse files Browse the repository at this point in the history
Filter out libraries we don't have permissions to before fetching
the related book offers, to reduce the amount of requests some more.
  • Loading branch information
lazka committed Jun 27, 2024
1 parent 75a7c7e commit 7399e8f
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions src/Service/AlmaApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 7399e8f

Please sign in to comment.