From defe8169763f0266b633bc801c7acda43715b8cb Mon Sep 17 00:00:00 2001 From: Rune Schjellerup Philosof Date: Fri, 15 Feb 2013 14:42:26 +0100 Subject: [PATCH 1/2] Load all the objects by stepping the webservice repeatedly. Yes, this will be slow for large lists! We might consider inserting a pager in the frontend. But it is nicer than the current loan lists missing some titles when the limit of 50 uncached objects are hit. opensearch limits stepValue to 50 (even though it doesn't say so in the documentation)... --- ting.client.inc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ting.client.inc b/ting.client.inc index c351a70..534640c 100644 --- a/ting.client.inc +++ b/ting.client.inc @@ -109,7 +109,11 @@ function ting_get_objects($ids) { $query[] = 'rec.id=' . $id; } } - if (sizeof($query)) { + $i = 0; + do { + if (sizeof($query) == 0) { + break; + } $request = ting_get_request_factory()->getSearchRequest(); if ($agency = variable_get('ting_agency', FALSE)) { @@ -122,8 +126,8 @@ function ting_get_objects($ids) { } $request->setQuery(join(' OR ', $query)); - $request->setStart(1); - $request->setNumResults(1000); + $request->setStart($i * 50 + 1); + $request->setNumResults(50); $request->setAllObjects(TRUE); $result = ting_execute_cache($request); @@ -137,7 +141,8 @@ function ting_get_objects($ids) { } } } - } + $i++; + } while ($result->more); return $objects; } From 58eac55738d609d26c1b217406d6d7cb6b49b3b8 Mon Sep 17 00:00:00 2001 From: Rune Schjellerup Philosof Date: Mon, 11 Mar 2013 15:56:46 +0100 Subject: [PATCH 2/2] Add a sprinkling of comments --- ting.client.inc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ting.client.inc b/ting.client.inc index 534640c..2832fb5 100644 --- a/ting.client.inc +++ b/ting.client.inc @@ -109,23 +109,25 @@ function ting_get_objects($ids) { $query[] = 'rec.id=' . $id; } } + // opensearch is limited to 50 results per call, so iterate until all have been fetched. $i = 0; do { + // I query is empty, then don't do it. + // Not necessary to do in each iteration, but it doesn't hurt much. if (sizeof($query) == 0) { break; } - $request = ting_get_request_factory()->getSearchRequest(); + $request = ting_get_request_factory()->getSearchRequest(); if ($agency = variable_get('ting_agency', FALSE)) { $request->setAgency($agency); } - $profile = variable_get('ting_search_profile', ''); if (!empty($profile) && method_exists($request, 'setProfile')) { $request->setProfile($profile); } - $request->setQuery(join(' OR ', $query)); + // Do it in steps of 50. $request->setStart($i * 50 + 1); $request->setNumResults(50); $request->setAllObjects(TRUE);