server/src/app/Services/BnfResolver.php
changeset 158 366509ae2f37
parent 133 821253d361d1
child 506 8a5bb4b48b85
--- a/server/src/app/Services/BnfResolver.php	Mon Apr 25 14:05:17 2016 +0200
+++ b/server/src/app/Services/BnfResolver.php	Sat May 07 10:06:26 2016 +0200
@@ -45,7 +45,13 @@
     public function getLabels(array $ids) {
 
         if(count($ids) > config('corpusparole.bnf_max_ids')) {
-            throw new BnfResolverException("Too manys ids provided");
+
+            return array_reduce(
+                array_map([$this, 'getLabels'], array_chunk($ids, config('corpusparole.bnf_max_ids'))),
+                'array_merge',
+                []
+            );
+            //throw new BnfResolverException("Too manys ids provided");
         }
 
         $bnfids = array_map([$this, 'checkBnfId'], $ids);
@@ -58,8 +64,10 @@
             $cachedValue = Cache::get("bnf:$bnfid");
             if(is_null($cachedValue)) {
                 array_push($missingBnfids, $bnfid);
+            } elseif (mb_strlen($cachedValue)>0) {
+                $results[$bnfidSource] = $cachedValue;
             } else {
-                $results[$bnfidSource] = $cachedValue;
+                $results[$bnfidSource] = null;
             }
         }
 
@@ -99,10 +107,10 @@
                 $results[$bnfidSource] = $missingValue;
             }
             else {
+                Cache::put("bnf:$bnfid", "", config('corpusparole.bnf_cache_expiration'));
                 $results[$bnfidSource] = null;
             }
         }
-
         return $results;
     }