From d4aace9e94d6cb655972782378e2441869537eaa Mon Sep 17 00:00:00 2001 From: Gilles Crettenand Date: Tue, 2 Jun 2015 22:51:51 +0200 Subject: [PATCH] move getting books by chung to base function --- NetBiblio.php | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/NetBiblio.php b/NetBiblio.php index 48aa5c4..f227794 100644 --- a/NetBiblio.php +++ b/NetBiblio.php @@ -64,6 +64,19 @@ class NetBiblio extends WebService * @throws WebException */ private function GetBooks(array $codes) { + // it is faster to do multiple small request to Solr rather than one big so separate + // in chunks if we are above the limit. 15 was found by testing and seems to be a sweet spot + $limit = 15; + $count = count($codes); + if(count($codes) > $limit) { + $parts = array_chunk($codes, $limit); + $books = array(); + foreach($parts as $p) { + $books = array_merge($books, $this->GetBooks($p)); + } + return $books; + } + $bs = new BookSearch(); $bs->addQuery('code:('.implode(' OR ', $codes).')', null, false); $results = $bs->getResults(0, count($codes)); @@ -398,23 +411,7 @@ class NetBiblio extends WebService public function FindBooks($codes) { $this->CheckSession(); - - $codes = json_decode($codes); - - // it is faster to do multiple small request to Solr rather than one big so separate - // in chunks if we are above the limit. 15 was found by testing and seems to be a sweet spot - $limit = 15; - if(count($codes) > $limit) { - $parts = array_chunk($codes, $limit); - $books = array(); - foreach($parts as $p) { - $books = array_merge($books, $this->GetBooks($p)); - } - } else { - $books = $this->GetBooks($codes); - } - - return $this->AddBookData($books); + return $this->AddBookData($this->GetBooks(json_decode($codes))); } public function FindBook($code)