fix: returning a list of only count limit when codes count > limit

This commit is contained in:
Guillermo Pages
2022-07-01 09:26:11 +02:00
parent bf49549002
commit 17fe057765

View File

@@ -289,21 +289,19 @@ class BookSearch
// in chunks if we are above the limit. 15 was found by testing and seems to be a sweet spot // in chunks if we are above the limit. 15 was found by testing and seems to be a sweet spot
$limit = 15; $limit = 15;
$count = count($codes); $count = count($codes);
if($count > $limit) {
$parts = array_chunk($codes, $limit);
$books = array();
foreach($parts as $p) {
// if we use array_merge here the numerical keys (book code) will be lost
$books += self::getBooks($p, $field);
}
return $books;
}
$bs = self::getLastInstance(); $bs = self::getLastInstance();
$parts = $count <= $limit ? [$codes] : array_chunk($codes, $limit);
$books = [];
foreach($parts as $p) {
// if we use array_merge here the numerical keys (book code) will be lost
$bs->addOrQuery($codes, $field); $bs->addOrQuery($codes, $field);
$results = $bs->getResults(0, $count); $results = $bs->getResults(0, $count);
return $results['books']; $foundBooks = $results['books'];
$books += $foundBooks;
}
return $books;
} }
public static function getTerms($field) { public static function getTerms($field) {