Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load all the objects by stepping the webservice repeatedly. #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions ting.client.inc
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,27 @@ function ting_get_objects($ids) {
$query[] = 'rec.id=' . $id;
}
}
if (sizeof($query)) {
$request = ting_get_request_factory()->getSearchRequest();
// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little typo I => If

// Not necessary to do in each iteration, but it doesn't hurt much.
if (sizeof($query) == 0) {
break;
}

$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));
$request->setStart(1);
$request->setNumResults(1000);
// Do it in steps of 50.
$request->setStart($i * 50 + 1);
$request->setNumResults(50);
$request->setAllObjects(TRUE);

$result = ting_execute_cache($request);
Expand All @@ -137,7 +143,8 @@ function ting_get_objects($ids) {
}
}
}
}
$i++;
} while ($result->more);
return $objects;
}

Expand Down